Revision 319:10ac9427a0da

View differences:

src/main/java/tt/jointeuclid2ni/probleminstance/TrajectoryCoordinationProblemImpl.java
54 54
    		DirectedGraph<Point, Line> planningGraph, Point[] docks, List<RelocationTask> relocationTasks) {
55 55
    	this(environment,starts, targets, bodyRadiuses, toFloatArr(maxSpeeds), planningGraph, docks, relocationTasks);
56 56
    }
57
    
58
    public TrajectoryCoordinationProblemImpl(Environment environment, Point[] starts, int[] bodyRadiuses, float[] maxSpeeds, 
59
    		DirectedGraph<Point, Line> planningGraph, Point[] docks) {
60
    	this(environment,starts, null, bodyRadiuses, maxSpeeds, planningGraph, docks, null);
61
    }
57 62

  
58 63
    private static float[] toFloatArr(int[] intArr) {
59 64
		float[] floatArr = new float[intArr.length];
src/main/java/tt/jointeuclid2ni/probleminstance/VisUtil.java
169 169

  
170 170
        }, new tt.euclid2i.vis.ProjectionTo2d()));
171 171
        
172
        tasksToggle.addSubLayer(ArrowLayer.create(new LineElements() {
173

  
174
            @Override
175
            public Color getColor() {
176
                return Color.BLUE;
177
            }
178

  
179
            @Override
180
            public int getStrokeWidth() {
181
                return 1;
182
            }
183

  
184
            @Override
185
            public Iterable<? extends cz.agents.alite.vis.element.Line> getLines() {
186
            	ArrayList<cz.agents.alite.vis.element.Line> lines = new ArrayList<cz.agents.alite.vis.element.Line>();
187
                for (int i = 0; i < problem.getStarts().length; i++) {
188
                	Point current = problem.getStart(i);
189
                	for (RelocationTask task : problem.getRelocationTasks(i)) {
190
                		Point next = task.getDestination();
191
                    	Point3d startLine = new Point3d(current.x, current.y, 0);
192
                    	Point3d endLine = new Point3d(next.x, next.y, 0);
193
                    	
194
                    	lines.add(new LineImpl(startLine, endLine));
195
                    	current = next;
196
                	}
197
                }
198
                
199
                return lines;
200
            }
201
        }));
202
        
203 172
        VisManager.registerLayer(tasksToggle);
204 173
        
205 174
        // Overlay
src/main/java/tt/jointeuclid2ni/probleminstance/generator/GenerateRTInstance.java
11 11
import java.util.List;
12 12
import java.util.Random;
13 13

  
14
import org.jgrapht.DirectedGraph;
15

  
14 16
import cz.agents.alite.communication.acquaintance.Plan;
17
import tt.euclid2i.Line;
15 18
import tt.euclid2i.Point;
16 19
import tt.euclid2i.discretization.LazyGrid;
20
import tt.euclid2i.probleminstance.Environment;
17 21
import tt.euclid2i.region.Rectangle;
18 22
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblem;
19 23
import tt.jointeuclid2ni.probleminstance.RelocationTask;
......
32 36
	private static final int FIRSTTASK = 5000;
33 37

  
34 38
	public static TrajectoryCoordinationProblem generateInstance(
35
			String environmentFile, int nAgents, int radius, float maxSpeed, int nEndpoints, int seed) throws ProblemNotCreatedException {
39
			String environmentFile, int nAgents, int radius, float maxSpeed, int seed) throws ProblemNotCreatedException {
36 40

  
37 41
		EarliestArrivalProblem inInstance = readProblem(environmentFile);
38 42
		Random rnd = new Random(seed);
39
		
40
		// first index is checkpoint number, second index is the robot number
41
		tt.euclidtime3i.Point[][] checkpoints = new tt.euclidtime3i.Point[nEndpoints][nAgents];
43
		Point[] starts = new Point[nAgents];
42 44

  
43 45
		// all endpoints without the starting positions
44
		LinkedList<Point> checkpointCandidates = new LinkedList<Point>(Arrays.asList(inInstance.getDocks()));	
46
		LinkedList<Point> midPoints = new LinkedList<Point>(Arrays.asList(inInstance.getDocks()));	
45 47
		
46 48
		// generate starting positions
47 49
		for (int j = 0; j < nAgents; j++) {
48
			Point point = randomVertex(checkpointCandidates, rnd);
49
			checkpoints[0][j] = new tt.euclidtime3i.Point(point, 0);
50
			checkpointCandidates.remove(point);
51
		}
52
					
53
		for (int i=1; i < nEndpoints-1; i++) {
54
			LinkedList<Point> freeDocks = new LinkedList<Point>(checkpointCandidates);			
55
			for (int j = 0; j < nAgents; j++) {
56
				Point point = randomVertex(freeDocks, rnd);
57
				checkpoints[i][j] = new tt.euclidtime3i.Point(point, FIRSTTASK);
58
				freeDocks.remove(point);
59
			}
60
		}
61
		
62
		// the final checkpoints are the same as the starting checkpoints
63
		for (int i = 0; i < checkpoints[0].length; i++) {
64
			checkpoints[nEndpoints-1][i] = new tt.euclidtime3i.Point(checkpoints[0][i].getPosition(), FIRSTTASK);
50
			starts[j] = randomVertex(midPoints, rnd);
51
			midPoints.remove(starts[j]);
65 52
		}
66 53
		
67 54
		int[] bodyRadiuses = new int[nAgents];
......
69 56

  
70 57
		float[] maxSpeeds = new float[nAgents];
71 58
		Arrays.fill(maxSpeeds, maxSpeed);
72
		
73
		Point[] starts = new Point[nAgents];
74
		for (int i = 0; i < nAgents; i++) {
75
			starts[i] = checkpoints[0][i].getPosition();
76
		}
77
		
78
		List<RelocationTask> tasks = new LinkedList<RelocationTask>();
79
		for (int i=1; i<nEndpoints;i++) {
80
			for (int agentId = 0; agentId < nAgents; agentId++) {
81
				tasks.add(new RelocationTaskImpl(checkpoints[i][agentId].getTime(), agentId, checkpoints[i][agentId].getPosition()));
82
			}
83
		}
84
		
59

  
85 60
		TrajectoryCoordinationProblem outInstance 
86
			= new TrajectoryCoordinationProblemImpl(inInstance.getEnvironment(), starts, bodyRadiuses, maxSpeeds, tasks, inInstance.getPlanningGraph());
61
			= new TrajectoryCoordinationProblemImpl(inInstance.getEnvironment(), starts, bodyRadiuses, maxSpeeds, inInstance.getPlanningGraph(), midPoints.toArray(new Point[0]));
87 62
		
88 63
		return outInstance;
89 64
	}
......
116 91
		int agents = Integer.parseInt(Args.getArgumentValue(args, "-nagents", true));
117 92
		int radius = Integer.parseInt(Args.getArgumentValue(args, "-radius", true));
118 93
		float maxSpeed = Float.parseFloat(Args.getArgumentValue(args, "-maxspeed", true));
119
		int nGoals = Integer.parseInt(Args.getArgumentValue(args, "-ngoals", true));
120 94
		int seed = Integer.parseInt(Args.getArgumentValue(args, "-seed", true));
121 95

  
122 96
		
123 97
		String outFile = Args.getArgumentValue(args, "-outfile", false);
124 98
		boolean showVis = Args.isArgumentSet(args, "-showvis");
125 99
		
126
		
127

  
128 100
		if (Args.isArgumentSet(args, "-verbose")) {
129 101
			Verbose.setVerbose(true);
130 102
		}
131 103

  
132 104
		TrajectoryCoordinationProblem instance = generateInstance(environmentFile,
133
				agents, radius, maxSpeed, nGoals+1, seed);
105
				agents, radius, maxSpeed, seed);
134 106

  
135 107
		PrintStream outStream = System.out;
136 108

  
src/main/java/tt/jointeuclid2ni/solver/Parameters.java
35 35
	public int noOfClusters;
36 36
	public int samplingInterval;
37 37
	public double simSpeed;
38
	public int nTasks;
38 39
}

Also available in: Unified diff