Revision 26:c6ab24e555d4

View differences:

src/main/java/tt/jointeuclid2ni/ProblemInstanceDesigner.java
1 1
package tt.jointeuclid2ni;
2 2

  
3 3
import java.awt.Color;
4
import java.io.File;
4 5

  
5 6
import javax.vecmath.Point2d;
6 7

  
7 8
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblem;
8 9
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblemXMLSerializer;
10
import tt.vis.PictureLayer;
9 11
import tt.vis.problemcreator.ProblemCreatedListener;
10 12
import tt.vis.problemcreator.ProblemCreatorLayer;
11 13
import cz.agents.alite.vis.VisManager;
12 14
import cz.agents.alite.vis.layer.common.ColorLayer;
13 15
import cz.agents.alite.vis.layer.common.VisInfoLayer;
16
import cz.agents.alite.vis.layer.terminal.ImageLayer;
14 17

  
15 18
public class ProblemInstanceDesigner {
16 19

  
17 20
    public static void main(String[] args) {
18 21
        // ---- initialize vizualization itself
19 22

  
20
        VisManager.setInitParam("Problem Instance Desginer", 1024, 768, 200, 200);
23
        VisManager.setInitParam("Problem Instance Designer", 1024, 768, 200, 200);
21 24
        VisManager.setSceneParam(new VisManager.SceneParams() {
22 25

  
23 26
            @Override
......
44 47
        // ---- add all the layers
45 48

  
46 49
        VisManager.registerLayer(ColorLayer.create(Color.WHITE));
50
        VisManager.registerLayer(PictureLayer.create(ImageLayer.loadImage(new File("/home/capino/projects/deconfliction/repo-doc/rss2014-iterative/figs/urbanC.png"))));
47 51
        VisManager.registerLayer(problemCreatorLayer);
48 52
        VisManager.registerLayer(VisInfoLayer.create());
49 53
        VisManager.init();
src/main/java/tt/jointeuclid2ni/solver/impl/AlgorithmIIHP.java
1 1
package tt.jointeuclid2ni.solver.impl;
2 2

  
3
import static tt.jointtraj.util.Util.getSumCost;
4

  
5
import java.util.List;
6
import java.util.Random;
7

  
3 8
import org.jgrapht.DirectedGraph;
4 9
import org.jscience.mathematics.number.Complex;
10

  
5 11
import tt.euclid2i.EvaluatedTrajectory;
6 12
import tt.euclid2i.Line;
7 13
import tt.euclid2i.Point;
......
20 26
import tt.util.Counters;
21 27
import tt.util.Verbose;
22 28

  
23
import java.util.List;
24
import java.util.Random;
25

  
26
import static tt.jointtraj.util.Util.getSumCost;
27

  
28 29

  
29 30
public class AlgorithmIIHP extends AbstractAlgorithm {
30 31

  
src/main/java/tt/jointtraj/homotopyiterative/LocalHClassPlanner.java
28 28

  
29 29
public class LocalHClassPlanner {
30 30

  
31
    private int agents;
31
    private int nAgents;
32 32
    private EvaluatedTrajectory[] trajectories;
33 33
    private int[] goalArrivalTime;
34 34
    private Complex[] hValues;
......
47 47
                              final HValueIntegrator integrator,
48 48
                              final int maxTime,
49 49
                              final int waitMoveDuration) {
50
        this.agents = missions.length;
50
        this.nAgents = missions.length;
51 51
        this.missions = missions;
52 52
        this.maxTime = maxTime;
53 53
        this.deadline = Long.MAX_VALUE;
54 54

  
55
        this.agentGraphs = new HomotopyWeightedTimeGraph[agents];
56
        this.optimalSingleAgentPolicies = new HeuristicToGoal[agents];
57
        this.goalArrivalTime = new int[agents];
55
        this.agentGraphs = new HomotopyWeightedTimeGraph[nAgents];
56
        this.optimalSingleAgentPolicies = new HeuristicToGoal[nAgents];
57
        this.goalArrivalTime = new int[nAgents];
58 58

  
59
        for (int i = 0; i < agents; i++) {
59
        for (int i = 0; i < nAgents; i++) {
60 60
            int[] separations = EarliestArrivalProblems.getRelativeSeparations(missions, i);
61 61
            agentGraphs[i] = new HomotopyWeightedTimeGraph(spatialGraph[i], missions[i].getTarget(),
62 62
                    integrator, separations, constraint, missions[i].getMaxSpeed(), maxTime, waitMoveDuration, missions[i].getTarget());
......
103 103
    }
104 104

  
105 105
    private void clearTemporalVariables() {
106
        trajectories = new EvaluatedTrajectory[agents];
107
        hValues = new Complex[agents];
106
        trajectories = new EvaluatedTrajectory[nAgents];
107
        hValues = new Complex[nAgents];
108 108
    }
109 109

  
110 110
    private LocalHClassSolution getSolution() {
......
113 113
    }
114 114

  
115 115
    private void applyPolicies(HValuePolicy[] policies) {
116
        for (int i = 0; i < agents; i++) {
116
        for (int i = 0; i < nAgents; i++) {
117 117
            agentGraphs[i].setPolicy(policies[i]);
118 118
        }
119 119
    }
120 120

  
121 121
    private void initializeSolutionWithoutConstraints(double maxCost) throws TrajectoryNotFoundException {
122
        for (int i = 0; i < agents; i++) {
122
        for (int i = 0; i < nAgents; i++) {
123 123
            Verbose.printf("Intial planning for agent %d. Sum of cost of others: %.2f. Cost left for me: %.2f\n", i, getTotalCostWithoutIthAgent(i),  maxCost - getTotalCostWithoutIthAgent(i));
124 124
            solveIthAgent(i, getOtherAgentsIds(i), 0, maxCost - getTotalCostWithoutIthAgent(i));
125 125
        }
......
128 128
    private void prioritizedPlanning(double maxCost) throws TrajectoryNotFoundException {
129 129

  
130 130

  
131
        for (int i = 0; i < agents; i++) {
131
        for (int i = 0; i < nAgents; i++) {
132 132

  
133 133
            Verbose.printf("Prioritized planning for agent %d. Sum of cost of others: %.2f. Cost left for me: %.2f\n", i, getTotalCostWithoutIthAgent(i),  maxCost - getTotalCostWithoutIthAgent(i));
134 134

  
......
145 145
        if (k < 3)
146 146
            return;
147 147

  
148
        int maxIterations = agents * (k - 2);
148
        int maxIterations = nAgents * (k - 2);
149 149
        for (int i = 0; i < maxIterations; i++) {
150
            int r = i % agents;
150
            int r = i % nAgents;
151 151
            double w = calculateSoftConstraintsWeight(i, maxIterations);
152 152

  
153 153
            Verbose.printf("Soft constraints planning w=%.2f for agent %d. Sum of cost of others: %.2f. Cost left for me: %.2f\n", w, r, getTotalCostWithoutIthAgent(r),  maxCost - getTotalCostWithoutIthAgent(r));
......
163 163
    private void recalculateWithHardConstraints(int k, double maxCost) throws TrajectoryNotFoundException {
164 164
        if (k < 2)
165 165
            return;
166
        for (int i = 0; i < agents; i++) {
166
        for (int i = 0; i < nAgents; i++) {
167 167
            Verbose.printf("Hard constraint planning for agent %d. Sum of cost of others: %.2f. Cost left for me: %.2f\n", i, getTotalCostWithoutIthAgent(i),  maxCost - getTotalCostWithoutIthAgent(i));
168 168
            solveIthAgent(i, getOtherAgentsIds(i), Double.POSITIVE_INFINITY, maxCost - getTotalCostWithoutIthAgent(i));
169 169
        }
......
203 203

  
204 204
    private int getLastAgentGoalArrivalTime(int skip) {
205 205
        int lastArrival = 0;
206
        for (int i = 0; i < agents; i++) {
206
        for (int i = 0; i < nAgents; i++) {
207 207
            if (i == skip)
208 208
                continue;
209 209

  
......
225 225
    }
226 226

  
227 227
    int[] getOtherAgentsIds(int myId) {
228
        int[] otherIds = new int[agents-1];
228
        int[] otherIds = new int[nAgents-1];
229 229
        int j=0;
230
        for (int i=0; i < agents; i++) {
230
        for (int i=0; i < nAgents; i++) {
231 231
            if (i != myId) {
232 232
                otherIds[j++] = i;
233 233
            }
......
255 255

  
256 256
    private double getTotalCostWithoutIthAgent(int skip) {
257 257
        double sumCost = 0;
258
        for (int i = 0; i < agents; i++) {
258
        for (int i = 0; i < nAgents; i++) {
259 259
            if (i == skip)
260 260
                continue;
261 261

  
src/main/resources/problems/environment/urbanC.xml
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<multiagentproblem>
3
<environment>
4
<obstacles>
5
<obstacle>
6
<point id="0">
7
<x>194</x>
8
<y>157</y>
9
</point>
10
<point id="1">
11
<x>196</x>
12
<y>388</y>
13
</point>
14
<point id="2">
15
<x>346</x>
16
<y>391</y>
17
</point>
18
<point id="3">
19
<x>345</x>
20
<y>158</y>
21
</point>
22
</obstacle>
23
<obstacle>
24
<point id="0">
25
<x>196</x>
26
<y>598</y>
27
</point>
28
<point id="1">
29
<x>345</x>
30
<y>598</y>
31
</point>
32
<point id="2">
33
<x>346</x>
34
<y>753</y>
35
</point>
36
<point id="3">
37
<x>196</x>
38
<y>751</y>
39
</point>
40
</obstacle>
41
<obstacle>
42
<point id="0">
43
<x>641</x>
44
<y>49</y>
45
</point>
46
<point id="1">
47
<x>639</x>
48
<y>202</y>
49
</point>
50
<point id="2">
51
<x>790</x>
52
<y>202</y>
53
</point>
54
<point id="3">
55
<x>794</x>
56
<y>49</y>
57
</point>
58
</obstacle>
59
<obstacle>
60
<point id="0">
61
<x>639</x>
62
<y>411</y>
63
</point>
64
<point id="1">
65
<x>639</x>
66
<y>564</y>
67
</point>
68
<point id="2">
69
<x>792</x>
70
<y>566</y>
71
</point>
72
<point id="3">
73
<x>792</x>
74
<y>412</y>
75
</point>
76
</obstacle>
77
<obstacle>
78
<point id="0">
79
<x>639</x>
80
<y>775</y>
81
</point>
82
<point id="1">
83
<x>639</x>
84
<y>925</y>
85
</point>
86
<point id="2">
87
<x>791</x>
88
<y>927</y>
89
</point>
90
<point id="3">
91
<x>792</x>
92
<y>776</y>
93
</point>
94
</obstacle>
95
</obstacles>
96
<bounds>
97
<point>
98
<x>0</x>
99
<y>0</y>
100
</point>
101
<point>
102
<x>1000</x>
103
<y>1000</y>
104
</point>
105
</bounds>
106
</environment>
107
<agents/>
108
</multiagentproblem>

Also available in: Unified diff