Ignore:
Timestamp:
2012-03-19T01:57:46+01:00 (13 years ago)
Author:
joshdoe
Message:

utilsplugin2: use improved assignment method for Replace Geometry (see #josm7295)

Location:
applications/editors/josm/plugins/utilsplugin2/src
Files:
11 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java

    r28045 r28116  
    11package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
    22
     3import edu.princeton.cs.algs4.AssignmentProblem;
    34import java.awt.geom.Area;
    45import java.awt.geom.Point2D;
     
    264265        }
    265266
    266         boolean useHungarian = Main.pref.getBoolean("utilsplugin2.replace-geometry.robustAssignment", false);
     267        boolean useRobust = Main.pref.getBoolean("utilsplugin2.replace-geometry.robustAssignment", true);
    267268       
    268269        // Find new nodes that are closest to the old ones, remove matching old ones from the pool
     
    270271        Map<Node, Node> nodeAssoc = new HashMap<Node, Node>();
    271272        if (geometryPool.size() > 0 && nodePool.size() > 0) {
    272             if (useHungarian) {  // use robust, but slower assignment
     273            if (useRobust) {  // use robust, but slower assignment
    273274                int gLen = geometryPool.size();
    274275                int nLen = nodePool.size();
    275                 double cost[][] = new double[nLen][gLen];
     276                int N = Math.max(gLen, nLen);
     277                double cost[][] = new double[N][N];
     278                for (int i = 0; i < N; i++) {
     279                    for (int j = 0; j < N; j++) {
     280                        cost[i][j] = Double.MAX_VALUE;
     281                    }
     282                }
    276283
    277284                double maxDistance = Double.parseDouble(Main.pref.get("utilsplugin2.replace-geometry.max-distance", "1"));
     
    286293                    }
    287294                }
    288                 int[][] assignment = HungarianAlgorithm.hgAlgorithm(cost, "min");
    289                 for (int i = 0; i < nLen; i++) {
    290                     int nIdx = assignment[i][0];
    291                     int gIdx = assignment[i][1];
     295                AssignmentProblem assignment = new AssignmentProblem(cost);
     296                for (int i = 0; i < N; i++) {
     297                    int nIdx = i;
     298                    int gIdx = assignment.sol(i);
    292299                    if (cost[nIdx][gIdx] != Double.MAX_VALUE) {
    293300                        nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx));
Note: See TracChangeset for help on using the changeset viewer.