Changeset 28298 in osm for applications/editors


Ignore:
Timestamp:
2012-04-14T17:31:42+02:00 (12 years ago)
Author:
joshdoe
Message:

[josm_utilsplugin2] Check iteration count to prevent endless loop with Replace Geometry (#josm7295)

Location:
applications/editors/josm/plugins/utilsplugin2/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/DijkstraSP.java

    r28116 r28298  
    4848        pq = new IndexMinPQ<Double>(G.V());
    4949        pq.insert(s, distTo[s]);
     50        int count = 0;
    5051        while (!pq.isEmpty()) {
    5152            int v = pq.delMin();
    5253            for (DirectedEdge e : G.adj(v))
    5354                relax(e);
     55            count++;
     56            if (count > G.V())
     57                throw new RuntimeException("Exceeded limit");
    5458        }
    5559
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java

    r28179 r28298  
    293293                    }
    294294                }
    295                 AssignmentProblem assignment = new AssignmentProblem(cost);
    296                 for (int i = 0; i < N; i++) {
    297                     int nIdx = i;
    298                     int gIdx = assignment.sol(i);
    299                     if (cost[nIdx][gIdx] != Double.MAX_VALUE) {
    300                         nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx));
     295                AssignmentProblem assignment;
     296                try {
     297                    assignment = new AssignmentProblem(cost);
     298                    for (int i = 0; i < N; i++) {
     299                        int nIdx = i;
     300                        int gIdx = assignment.sol(i);
     301                        if (cost[nIdx][gIdx] != Double.MAX_VALUE) {
     302                            nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx));
     303                        }
    301304                    }
    302                 }
    303                 // node will be moved, remove from pool
    304                 for (Node n : nodeAssoc.values()) {
    305                     nodePool.remove(n);
    306                 }
    307             } else { // use simple, faster, but less robust assignment method
     305                    // node will be moved, remove from pool
     306                    for (Node n : nodeAssoc.values()) {
     307                        nodePool.remove(n);
     308                    }
     309                }
     310                catch (Exception e) {
     311                    useRobust = false;
     312                    JOptionPane.showMessageDialog(Main.parent,
     313                            tr("Exceeded iteration limit for robust method, using simpler method."),
     314                            TITLE, JOptionPane.WARNING_MESSAGE);
     315                    nodeAssoc = new HashMap<Node, Node>();
     316                }
     317            }
     318            if (!useRobust) { // use simple, faster, but less robust assignment method
    308319                for (Node n : geometryPool) {
    309320                    Node nearest = findNearestNode(n, nodePool);
Note: See TracChangeset for help on using the changeset viewer.