I couldn't find a method in sim.field.network.Network like areNeighbors(Object o1, Object o2).
So a starting point would be to use Network's getEdges method and iterate through the returned Bag looking for the other agent node in the edges. You could write a thin wrapper method to do the job and you would have a reusable component, like:
public boolean areNeighbors(Network network, Object agentA, Object agentB) {
Bag edges = network.getEdges(agentA, null); //obtain all edges that have agentA; the bag may be empty but it won't be null
Iterator<Edge> iter = edges.iterator();
while (iter.hasNext()) { //iterate through all edges until we find agentB
Edge e = iter.next();
if (e.getOtherNode(agentA)==agentB) { //use agentA as one node and see if the other node is agentB
return true; //found it
}
}
return false; //did not find it
}
Then to achieve what you originally asked:
if ( !areNeighbors(mynetwork, agentA,agentB)) {
mynetwork.addEdge(agentA,agentB,null);
}
Tony