Search in sources :

Example 1 with NodesShift

use of org.vcell.util.graphlayout.NodesShift in project vcell by virtualcell.

the class ShootAndCutMinimizer method minimize.

public void minimize(EnergySum energySum) {
    ContainedGraph graph = energySum.getGraph();
    for (Node node : graph.getNodes()) {
        double shiftX = ContainedGraphUtil.getRandomShiftX(node, random);
        double shiftY = ContainedGraphUtil.getRandomShiftY(node, random);
        while (Math.abs(shiftX) + Math.abs(shiftY) > 0.3) {
            NodesShift nodesShift = new NodesShift.SingleNode(graph, node, shiftX, shiftY);
            if (energySum.getDifference(nodesShift) < 0) {
                nodesShift.apply();
                break;
            }
            shiftX = (1 - cut) * shiftX;
            shiftY = (1 - cut) * shiftY;
        }
    }
}
Also used : NodesShift(org.vcell.util.graphlayout.NodesShift) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ContainedGraph(org.vcell.util.graphlayout.ContainedGraph)

Example 2 with NodesShift

use of org.vcell.util.graphlayout.NodesShift in project vcell by virtualcell.

the class WerewolfMinimizer method minimize.

public void minimize(EnergySum energySum) {
    ContainedGraph graph = energySum.getGraph();
    NodesShift.Default nodesShift = new NodesShift.Default(graph);
    for (int iIteration = 0; iIteration < nIterations; ++iIteration) {
        double absShiftMax = 0;
        for (Node node : graph.getNodes()) {
            double shiftX = ContainedGraphUtil.getRandomShiftX(node, random);
            double shiftY = ContainedGraphUtil.getRandomShiftY(node, random);
            nodesShift.getShifts().put(node, new Vector2D(shiftX, shiftY));
            double absShiftX = Math.abs(shiftX);
            if (absShiftX > absShiftMax) {
                absShiftMax = absShiftX;
            }
            double absShiftY = Math.abs(shiftY);
            if (absShiftY > absShiftMax) {
                absShiftMax = absShiftY;
            }
        }
        while (absShiftMax > 0.3) {
            for (Map.Entry<Node, Vector2D> entry : nodesShift.getShifts().entrySet()) {
                Vector2D vShift = entry.getValue();
                vShift.x *= (1 - cut);
                vShift.y *= (1 - cut);
            }
            if (energySum.getDifference(nodesShift) < 0) {
                nodesShift.apply();
                break;
            }
            absShiftMax *= (1 - cut);
        }
    }
}
Also used : Vector2D(org.vcell.util.geometry2d.Vector2D) NodesShift(org.vcell.util.graphlayout.NodesShift) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ContainedGraph(org.vcell.util.graphlayout.ContainedGraph) Map(java.util.Map)

Aggregations

ContainedGraph (org.vcell.util.graphlayout.ContainedGraph)2 Node (org.vcell.util.graphlayout.ContainedGraph.Node)2 NodesShift (org.vcell.util.graphlayout.NodesShift)2 Map (java.util.Map)1 Vector2D (org.vcell.util.geometry2d.Vector2D)1