Revision 223:9983bf748618

View differences:

src/main/java/tt/jointeuclid2ni/probleminstance/generator/TriangulationGenerator.java
9 9
import java.util.Arrays;
10 10
import java.util.Collection;
11 11
import java.util.Collections;
12
import java.util.HashSet;
12 13
import java.util.Iterator;
13 14
import java.util.LinkedList;
14 15
import java.util.List;
16
import java.util.Queue;
17
import java.util.Set;
15 18

  
16 19
import org.apache.commons.lang3.ArrayUtils;
17 20
import org.jgrapht.DirectedGraph;
21
import org.jgrapht.Graphs;
18 22

  
19 23
import cz.agents.alite.vis.VisManager;
20 24
import tt.euclid2i.Line;
......
45 49
        String connectionRadiusStr = Args.getArgumentValue(args, "-connectionradius", false);
46 50
        String bodyRadiusStr = Args.getArgumentValue(args, "-bodyradius", false);
47 51
        
48
        boolean addDocks = Args.isArgumentSet(args, "-docks");
52
        boolean addBoundaryDocks = Args.isArgumentSet(args, "-boundarydocks");
53
        boolean addSparseDocks = Args.isArgumentSet(args, "-sparsedocks");
49 54
        boolean showVis = Args.isArgumentSet(args, "-showvis");
50 55

  
51 56
        final int dispersion = Integer.parseInt(dispersionStr);
......
90 95
			docks.addAll(Arrays.asList(brokenBoundary.getPoints()));
91 96
		}
92 97
        
93
		if (addDocks) {
98
		if (addBoundaryDocks) {
99
			for (Iterator<Point> iterator = docks.iterator(); iterator.hasNext();) {
100
				Point dock = iterator.next();
101
				if (!Util.isInFreeSpace(dock, boundaryRegionDeflated, inflatedObstacles)) {
102
					iterator.remove();
103
				}
104
			}
94 105
			docks = Util.selectDispersedPoints(docks, 2*bodyRadius+1);
95
		}
96

  
97
        
98
//        Collection<Region> polygonsForGraphBoundary = new LinkedList<Region>();
99
//        polygonsForGraphBoundary.addAll(Util.inflateRegions(obstacles, bodyRadius+1));
100
//        polygonsForGraphBoundary.addAll(Util.inflateRegions(Collections.singleton(boundaryRegion), bodyRadius+1));                
101
        
106
		} 
102 107

  
103 108
		DirectedGraph<Point, Line> planningGraph 
104 109
			= new GridBasedRoadmap(dispersion, connectionRadius, customPoints.toArray(new Point[0]), boundaryRegionDeflated, inflatedObstacles);
105 110

  
111
		
112
		if (addSparseDocks){
113
			docks = constructSparseDocks(planningGraph, boundaryRegion, obstacles, 2*bodyRadius+1, bodyRadius);
114
		}
115
		
106 116
        if (showVis) {
107 117
            VisUtil.visualizeGraph(planningGraph, boundaryRegionDeflated);
108 118
            
......
126 136
				problem.getEnvironment(), problem.getStarts(),
127 137
				problem.getTargets(), problem.getBodyRadiuses(),
128 138
				problem.getMaxSpeeds(), planningGraph,
129
				addDocks ? docks.toArray(new Point[0]) : null);
139
				addBoundaryDocks ? docks.toArray(new Point[0]) : null);
130 140

  
131 141
        PrintStream outStream = System.out;
132 142

  
......
136 146

  
137 147
        EarliestArrivalProblemXMLSerializer.serialize(augmentedProblem, outStream);
138 148
    }
149
    
150
    /** 
151
     * finds a set of points that are 
152
     * a) at least given distance from each otgher 
153
     * b) at least given distance from the nearest obstacle/boundary.
154
     **/
155
	private static Collection<Point> constructSparseDocks(
156
		DirectedGraph<Point, Line> planningGraph, Region boundaryRegion,
157
		Collection<Region> obstacles, int clearance, int radius) {
158
		
159
		Collection<Region> boundaryRegionDeflated = Util.inflateRegions(Collections.singleton(boundaryRegion), clearance+radius);
160

  
161
        final Collection<Region> inflatedObstacles = new LinkedList<Region>();
162
        inflatedObstacles.addAll(Util.inflateRegions(obstacles, clearance+radius));
163
        
164
        LinkedList<Point> sparsePoints = new LinkedList<Point>();
165
        Queue<Point> open = new LinkedList<Point>();
166
        Set<Point> closed = new HashSet<Point>();
167
        
168
        open.add(planningGraph.vertexSet().iterator().next());
169
        
170
        while (!open.isEmpty()) {
171
        	Point current = open.poll();
172
        	
173
        	if (Util.distanceToNearestPoint(current, sparsePoints) > clearance+2*radius 
174
        			&& Util.isInFreeSpace(current, boundaryRegionDeflated, inflatedObstacles)) {
175
        		sparsePoints.add(current);
176
        	}
177
        	
178
        	for (Line edge : planningGraph.outgoingEdgesOf(current)) {
179
        		Point neighbor = Graphs.getOppositeVertex(planningGraph, edge, current);
180
        		if (!closed.contains(neighbor)) {
181
        			open.offer(neighbor);
182
        			closed.add(neighbor);
183
        		}
184
        	}
185
        }
186
		
187
		return sparsePoints;
188
	}
139 189
}

Also available in: Unified diff