Revision 141:12a22c833fc6

View differences:

src/main/java/tt/jointeuclid2ni/demo/ODDemo.java
1 1
package tt.jointeuclid2ni.demo;
2 2

  
3
import java.awt.Color;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7
import java.util.Arrays;
8
import java.util.Collection;
9
import java.util.HashSet;
10
import java.util.LinkedList;
11
import java.util.Set;
12

  
13
import javax.vecmath.Point2d;
14

  
3
import cz.agents.alite.vis.VisManager;
4
import cz.agents.alite.vis.layer.common.ColorLayer;
5
import cz.agents.alite.vis.layer.common.VisInfoLayer;
6
import cz.agents.alite.vis.layer.toggle.KeyToggleLayer;
15 7
import org.jgrapht.DirectedGraph;
16 8
import org.jgrapht.Graph;
17 9
import org.jgrapht.GraphPath;
......
19 11
import org.jgrapht.util.HeuristicToGoal;
20 12
import org.jgrapht.util.heuristics.HeuristicProvider;
21 13
import org.jgrapht.util.heuristics.PerfectHeuristic;
22

  
23 14
import tt.euclid2i.Line;
24 15
import tt.euclid2i.Point;
25 16
import tt.euclid2i.Region;
26 17
import tt.euclid2i.Trajectory;
27 18
import tt.euclid2i.discretization.AdditionalPointsExtension;
28 19
import tt.euclid2i.discretization.LazyGrid;
29
import tt.euclid2i.region.Rectangle;
20
import tt.euclid2i.probleminstance.DiscretizedEnvironmentImpl;
21
import tt.euclid2i.probleminstance.Environment;
22
import tt.euclid2i.probleminstance.RandomEnvironment;
30 23
import tt.euclid2i.util.Util;
31 24
import tt.euclid2i.vis.RegionsLayer;
32 25
import tt.euclidtime3i.vis.TimeParameter;
......
37 30
import tt.jointeuclid2ni.operatordecomposition.utils.ODGoal;
38 31
import tt.jointeuclid2ni.operatordecomposition.utils.ODHeuristic;
39 32
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblem;
40
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblemXMLDeserializer;
41
import tt.jointeuclid2ni.probleminstance.generator.ConflictGenerator;
42
import tt.jointeuclid2ni.probleminstance.generator.exception.ProblemNotCreatedException;
33
import tt.jointeuclid2ni.probleminstance.generator.ProblemGenerator;
34
import tt.jointeuclid2ni.probleminstance.generator.missions.MissionBases;
43 35
import tt.util.AgentColors;
44
import tt.vis.ColoredTrajectoriesLayer;
45
import tt.vis.FastAgentsLayer;
46
import tt.vis.GraphLayer;
47
import tt.vis.LabeledPointLayer;
48
import tt.vis.ParameterControlLayer;
49
import cz.agents.alite.vis.VisManager;
50
import cz.agents.alite.vis.layer.common.ColorLayer;
51
import cz.agents.alite.vis.layer.common.VisInfoLayer;
52
import cz.agents.alite.vis.layer.toggle.KeyToggleLayer;
36
import tt.vis.*;
37

  
38
import javax.vecmath.Point2d;
39
import java.awt.*;
40
import java.util.*;
53 41

  
54 42
public class ODDemo {
55 43

  
44
    //TODO does not work with 50/50 settings!
45

  
56 46
    private static final int AGENTS = 2;
57
    private static final int BODY_RADIUS = 50;
58
    private static final int GRID_STEP = 50;
47
    private static final int BODY_RADIUS = 60;
48
    private static final int GRID_STEP = 30;
59 49
    private static final int SPEED = 1;
60
    private static final int MAXTIME = 3000;
50
    private static final int SEED = 10;
51
    private static final int MAX_TIME = 3000;
61 52
    private static final int[][] PATTERN = LazyGrid.PATTERN_4_WAY;
62 53

  
63 54
    private Trajectory[] solution;
......
67 58
    }
68 59

  
69 60
    private EarliestArrivalProblem getProblem() {
70
        EarliestArrivalProblem problem = null;
71
        try {
72
            FileInputStream inputStream = new FileInputStream(new File("src/main/resources/problems/urbanmc.xml"));
73
            EarliestArrivalProblem serializedEnv = EarliestArrivalProblemXMLDeserializer.deserialize(inputStream);
74
            int[] bodyRadiuses = new int[AGENTS];
75
            Arrays.fill(bodyRadiuses, BODY_RADIUS);
76
            problem = ConflictGenerator.generateSingleInstance(serializedEnv.getEnvironment(), null, bodyRadiuses, PATTERN, GRID_STEP, 13, new Rectangle(new Point(250, 250), new Point(750, 750)));
77
        } catch (FileNotFoundException e) {
78
            e.printStackTrace();
79
        } catch (ProblemNotCreatedException e) {
80
            e.printStackTrace();
81
        }
82
        return problem;
61
        Environment environment = new RandomEnvironment(1000, 1000, 5, 300, SEED);
62
        DirectedGraph<Point, Line> graph = LazyGrid.zeroOriginGrid(environment, PATTERN, GRID_STEP).generateFullGraph();
63

  
64
        DiscretizedEnvironmentImpl discretizedEnvironment = new DiscretizedEnvironmentImpl(environment, graph);
65
        MissionBases bases = new MissionBases(BODY_RADIUS, SPEED, MAX_TIME);
66

  
67
        return ProblemGenerator.generateInstance(discretizedEnvironment, bases, AGENTS, SEED);
83 68
    }
84 69

  
85 70
    public void create() {
......
97 82
        ODNode start = ODNode.start(problem.getStarts(), goal, problem.getBodyRadiuses(), GRID_STEP);
98 83

  
99 84
        initVisualization();
100
        visualizeProblem(getProblem(), graph[argmin(problem.getBodyRadiuses())]);
85
        visualizeProblem(problem, problem.getPlanningGraph());
101 86

  
102 87
        GraphPath<ODNode, ODEdge> path = AStarShortestPathSimple.findPathBetween(odWrapper, odHeuristic, start, goal);
103
        solution = ODUtils.toTrajectories(path, MAXTIME, SPEED, GRID_STEP);
88
        solution = ODUtils.toTrajectories(path, MAX_TIME, SPEED, GRID_STEP);
104 89
    }
105 90

  
106 91
    private Graph<Point, Line>[] createGraphs(EarliestArrivalProblem problem) {
107 92
        Graph<Point, Line> graph[] = new Graph[problem.nAgents()];
108
        for (int i = 0; i < problem.nAgents(); i++) {
109
            graph[i] = createGrid(problem, i);
110
        }
93
        Arrays.fill(graph, problem.getPlanningGraph());
111 94
        return graph;
112 95
    }
113 96

  
......
195 178

  
196 179
            @Override
197 180
            public Graph<Point, Line> getGraph() {
198
                return ((AdditionalPointsExtension) graph).generateFullGraph(problem.getStart(0));
181
                return problem.getPlanningGraph();
199 182
            }
200 183
        }, new tt.euclid2i.vis.ProjectionTo2d(), Color.GRAY, Color.GRAY, 1, 4));
201 184

  
......
211 194
                    public Color getColor(int i) {
212 195
                        return AgentColors.getColorForAgent(i);
213 196
                    }
214
                }, new tt.euclid2i.vis.ProjectionTo2d(), 10, MAXTIME, 6, 's'
197
                }, new tt.euclid2i.vis.ProjectionTo2d(), 10, MAX_TIME, 6, 's'
215 198
        ));
216 199
        bKeyLayer.addSubLayer(FastAgentsLayer.create(
217 200
                new FastAgentsLayer.TrajectoriesProvider() {

Also available in: Unified diff