use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class Vicinity method findRangeD.
// **********====== This finds the range when Edge is Directed ============*********************
private int findRangeD(Edge edge, int chunksize) {
Set<Edge> edges = new HashSet<>();
// It matters whether Node1 is the tail or the head of the arrow
// Because of how the Edge class works, it looks like Node1 is ALWAYS the TAIL
NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT);
int range = 0 - chunksize;
while (edges.isEmpty()) {
// increment range by chunk
range += chunksize;
// create separate range values for x y and z, scaled by xdist ydist zdist
int xrange = (int) Math.ceil(range / xDist);
int yrange = (int) Math.ceil(range / yDist);
int zrange = (int) Math.ceil(range / zDist);
// initialize the edge sets
Set<Edge> node1edges1 = new HashSet<>();
Set<Edge> node1edges2 = new HashSet<>();
// list edges with either endpoint near node1
for (int x = getX(edge.getNode1(), locationMap) - xrange; x <= getX(edge.getNode1(), locationMap) + xrange; x++) {
for (int y = getY(edge.getNode1(), locationMap) - yrange; y <= getY(edge.getNode1(), locationMap) + yrange; y++) {
for (int z = getZ(edge.getNode1(), locationMap) - zrange; z <= getZ(edge.getNode1(), locationMap) + zrange; z++) {
if (x < xLow || x > xHigh || y < yLow || y > yHigh || z < zLow || z > zHigh)
continue;
if (Coords1.get(Arrays.asList(x, y, z)) != null)
node1edges1.addAll(Coords1.get(Arrays.asList(x, y, z)));
if (Coords2.get(Arrays.asList(x, y, z)) != null)
node1edges2.addAll(Coords2.get(Arrays.asList(x, y, z)));
}
}
}
// it's okay if the edges in node1edges2 are unidrected, though
if (!node1edges2.isEmpty()) {
List<Edge> edges12 = new ArrayList<>(node1edges2);
for (Edge thisedge : edges12) {
if (thisedge.isDirected())
node1edges2.remove(thisedge);
}
}
int x2 = getX(edge.getNode2(), locationMap);
int y2 = getY(edge.getNode2(), locationMap);
int z2 = getZ(edge.getNode2(), locationMap);
// if one or both of the above lists is nonempty, find edges where the other endpoint is near node2!
if (!node1edges1.isEmpty()) {
for (Edge edge11 : node1edges1) {
int x = getX(edge11.getNode2(), locationMap);
int y = getY(edge11.getNode2(), locationMap);
int z = getZ(edge11.getNode2(), locationMap);
if (x >= x2 - xrange && x <= x2 + xrange && y >= y2 - yrange && y <= y2 + yrange && z >= z2 - zrange && z <= z2 + zrange) {
edges.add(edge11);
}
}
}
if (!node1edges2.isEmpty()) {
for (Edge edge12 : node1edges2) {
int x = getX(edge12.getNode1(), locationMap);
int y = getY(edge12.getNode1(), locationMap);
int z = getZ(edge12.getNode1(), locationMap);
if (x >= x2 - xrange && x <= x2 + xrange && y >= y2 - yrange && y <= y2 + yrange && z >= z2 - zrange && z <= z2 + zrange) {
edges.add(edge12);
}
}
}
// System.out.println("edges is empty?"+edges.isEmpty()+" at range "+range);
// System.out.println(edges);
}
return range;
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class AbstractWorkbench method toggleEndpoint.
private void toggleEndpoint(IDisplayEdge graphEdge, int endpointNumber) {
Edge edge = graphEdge.getModelEdge();
Edge newEdge;
if (endpointNumber == 1) {
Endpoint endpoint = edge.getEndpoint1();
Endpoint nextEndpoint;
if (endpoint == Endpoint.TAIL) {
nextEndpoint = Endpoint.ARROW;
} else if (endpoint == Endpoint.ARROW) {
nextEndpoint = Endpoint.CIRCLE;
} else {
nextEndpoint = Endpoint.TAIL;
}
newEdge = new Edge(edge.getNode1(), edge.getNode2(), nextEndpoint, edge.getEndpoint2());
} else if (endpointNumber == 2) {
Endpoint endpoint = edge.getEndpoint2();
Endpoint nextEndpoint;
if (endpoint == Endpoint.TAIL) {
nextEndpoint = Endpoint.ARROW;
} else if (endpoint == Endpoint.ARROW) {
nextEndpoint = Endpoint.CIRCLE;
} else {
nextEndpoint = Endpoint.TAIL;
}
newEdge = new Edge(edge.getNode1(), edge.getNode2(), edge.getEndpoint1(), nextEndpoint);
} else {
throw new IllegalArgumentException("Endpoint number should be 1 or 2.");
}
getGraph().removeEdge(edge);
try {
boolean added = getGraph().addEdge(newEdge);
if (!added) {
getGraph().addEdge(edge);
return;
}
} catch (IllegalArgumentException e) {
getGraph().addEdge(edge);
return;
}
repaint();
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class AbstractWorkbench method removeEdge.
/**
* Removes the given display edge from the workbench by requesting that the
* model remove the corresponding model edge.
*/
private void removeEdge(IDisplayEdge displayEdge) {
if (displayEdge == null) {
return;
}
Edge modelEdge = (Edge) (getDisplayToModel().get(displayEdge));
try {
getGraph().removeEdge(modelEdge);
firePropertyChange("modelChanged", null, null);
} catch (Exception e) {
if (isNodeEdgeErrorsReported()) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e.getMessage());
}
}
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class AbstractWorkbench method handleMouseEntered.
private void handleMouseEntered(MouseEvent e) {
Object source = e.getSource();
if (source instanceof DisplayEdge) {
IDisplayEdge displayEdge = (DisplayEdge) source;
Edge edge = displayEdge.getModelEdge();
if (graph.containsEdge(edge)) {
// Bootstrapping Distribution
List<EdgeTypeProbability> edgeProb = edge.getEdgeTypeProbabilities();
if (edgeProb != null) {
String endpoint1 = edge.getEndpoint1().toString();
switch(endpoint1) {
case "Tail":
endpoint1 = "-";
break;
case "Arrow":
endpoint1 = "<";
break;
case "Circle":
endpoint1 = "o";
break;
case "Star":
endpoint1 = "*";
break;
case "Null":
endpoint1 = "Null";
break;
}
String endpoint2 = edge.getEndpoint2().toString();
switch(endpoint2) {
case "Tail":
endpoint2 = "-";
break;
case "Arrow":
endpoint2 = ">";
break;
case "Circle":
endpoint2 = "o";
break;
case "Star":
endpoint2 = "*";
break;
case "Null":
endpoint2 = "Null";
break;
}
String text = "<html>" + edge.getNode1().getName() + " " + endpoint1 + "-" + endpoint2 + " " + edge.getNode2().getName() + "<br>";
String n1 = edge.getNode1().getName();
String n2 = edge.getNode2().getName();
List<String> nodes = new ArrayList<>();
nodes.add(n1);
nodes.add(n2);
Collections.sort(nodes);
for (EdgeTypeProbability edgeTypeProb : edgeProb) {
String _type = "" + edgeTypeProb.getEdgeType();
switch(edgeTypeProb.getEdgeType()) {
case nil:
_type = "no edge";
break;
case ta:
_type = "-->";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case at:
_type = "<--";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case ca:
_type = "o->";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case ac:
_type = "<-o";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case cc:
_type = "o-o";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case aa:
_type = "<->";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
case tt:
_type = "---";
_type = nodes.get(0) + " " + _type + " " + nodes.get(1);
break;
default:
break;
}
if (edgeTypeProb.getProbability() > 0) {
text += "[" + _type + "]:" + String.format("%.4f", edgeTypeProb.getProbability());
text += "<br>";
}
}
// Commented out by Zhou
// JLabel edgeTypeDistLabel = new JLabel(text);
// edgeTypeDistLabel.setOpaque(true);
// edgeTypeDistLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// setEdgeLabel(edge, edgeTypeDistLabel);
// Use tooltip instead of label - Added by Zhou
setEdgeToolTip(edge, text);
}
}
}
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class AbstractWorkbench method resetEdgeOffsets.
/**
* Scans through all edges between two nodes, resets those edge's offset
* values. Note that these offsets are stored in the edges themselves so
* this does not have to be recomputed all the time
*/
private void resetEdgeOffsets(IDisplayEdge graphEdge) {
try {
DisplayNode displayNode1 = graphEdge.getNode1();
DisplayNode displayNode2 = graphEdge.getNode2();
Node node1 = displayNode1.getModelNode();
Node node2 = displayNode2.getModelNode();
Graph graph = getGraph();
List<Edge> edges = graph.getEdges(node1, node2);
for (int i = 0; i < edges.size(); i++) {
Edge edge = edges.get(i);
Node _node1 = edge.getNode1();
boolean awayFrom = (_node1 == node1);
IDisplayEdge displayEdge = (IDisplayEdge) getModelEdgesToDisplay().get(edge);
if (displayEdge != null) {
displayEdge.setOffset(calcEdgeOffset(i, edges.size(), 35, awayFrom));
}
}
} catch (UnsupportedOperationException e) {
// This happens for the session workbench. The getEdges() method
// is not implemented for it. Not sure if we'll ever need it to
// be implemented. jdramsey 4/14/2004
}
}
Aggregations