Revision 136:6c698a4b70bf

View differences:

misc/eclipse/GenerateInstance.launch
8 8
</listAttribute>
9 9
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
10 10
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="tt.jointeuclid2ni.probleminstance.generator.GenerateInstance"/>
11
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-env src/main/resources/environments/78_obstacles.xml -nagents 5 -radius 18 -seed 1000 -outfile src/main/resources/problems/78_obstacles.xml"/>
11
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-env src/main/resources/environments/78_obstacles.xml -nagents 5 -radius 10 -seed 1000 -gridpattern 4 -gridstep 20 -outfile src/main/resources/problems/78_obstacles.xml -showvis"/>
12 12
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="deconflictiontools"/>
13 13
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
14 14
</launchConfiguration>
src/main/java/tt/jointeuclid2ni/probleminstance/VisUtil.java
64 64
        // background
65 65
        VisManager.registerLayer(ColorLayer.create(Color.WHITE));
66 66

  
67
        // boundary 
67
        // boundary
68 68
        VisManager.registerLayer(RegionsLayer.create(
69 69
                new RegionsLayer.RegionsProvider() {
70 70

  
......
139 139

  
140 140
            @Override
141 141
            public Collection<? extends Region> getRegions() {
142
                return inflatedObstacles;
142
            	if (inflatedObstacles == null) {
143
            		return Collections.EMPTY_LIST;
144
            	} else {
145
            		return inflatedObstacles;
146
            	}
143 147
            }
144 148
        }, Color.YELLOW));
145 149

  
src/main/java/tt/jointeuclid2ni/probleminstance/generator/GenerateInstance.java
13 13
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblem;
14 14
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblemXMLDeserializer;
15 15
import tt.jointeuclid2ni.probleminstance.EarliestArrivalProblemXMLSerializer;
16
import tt.jointeuclid2ni.probleminstance.VisUtil;
16 17
import tt.jointeuclid2ni.probleminstance.generator.exception.ProblemNotCreatedException;
17 18
import tt.util.Args;
18 19
import tt.util.Verbose;
19 20

  
20 21
public class GenerateInstance {
21 22

  
22
    private boolean verbose = false;
23
    private String environmentFile;
24
    private int agents;
25
    private int radius;
26
    private int patternNumber;
27
    private int step;
28
    private int seed;
29
    private String outputFile;
30
    private Rectangle missionArea;
23
	public static EarliestArrivalProblem generateInstance(
24
			String environmentFile, int agents, int radius, int patternNumber,
25
			int step, int seed, Rectangle missionArea) throws ProblemNotCreatedException {
31 26

  
32
    public GenerateInstance(String environmentFile, int agents, int radius, int patternNumber, int step, int seed, Rectangle missionArea) {
33
        this.environmentFile = environmentFile;
34
        this.agents = agents;
35
        this.radius = radius;
36
        this.patternNumber = patternNumber;
37
        this.step = step;
38
        this.seed = seed;
39
        this.missionArea = missionArea;
40
    }
27
        boolean verbose = false;
41 28

  
42
    private void run(PrintStream output) throws ProblemNotCreatedException {
43 29
        Verbose.setVerbose(verbose);
44 30

  
45 31
        EarliestArrivalProblem problem = readProblem(environmentFile);
......
51 37

  
52 38
        int[] bodyRadiuses = prefillBodyRadiuses(agents, radius);
53 39

  
54
        EarliestArrivalProblem instance = ConflictGenerator
40
         EarliestArrivalProblem instance = ConflictGenerator
55 41
                .generateSingleInstance(problem.getEnvironment(), problem.getPlanningGraph(),
56 42
                        bodyRadiuses, pattern,
57
                        this.step, seed,
43
                        step, seed,
58 44
                        missionArea);
59 45

  
60
        EarliestArrivalProblemXMLSerializer.serialize(instance, output);
46
        return instance;
47

  
48

  
61 49
    }
62 50

  
63
    private int[] prefillBodyRadiuses(int agents, int radius) {
51
    private static int[] prefillBodyRadiuses(int agents, int radius) {
64 52
        int[] bodyRadiuses = new int[agents];
65 53
        Arrays.fill(bodyRadiuses, radius);
66 54
        return bodyRadiuses;
67 55
    }
68 56

  
69
    private int[][] getLazyGridPattern(int patternNumber) {
57
    private static int[][] getLazyGridPattern(int patternNumber) {
70 58
        int[][] pattern;
71 59
        switch (patternNumber) {
72 60
            case 4:
......
84 72
        return pattern;
85 73
    }
86 74

  
87
    private EarliestArrivalProblem readProblem(String environmentFile) {
75
    private static EarliestArrivalProblem readProblem(String environmentFile) {
88 76
        EarliestArrivalProblem problem;
89 77

  
90 78
        try {
91 79
            File file = new File(environmentFile);
92 80
            FileInputStream inputStream = new FileInputStream(file);
93 81
            problem = EarliestArrivalProblemXMLDeserializer.deserialize(inputStream);
94
            outputFile = file.getName();
95 82
        } catch (FileNotFoundException e) {
96 83
            throw new RuntimeException("Environment could not be loaded");
97 84
        }
......
99 86
        return problem;
100 87
    }
101 88

  
102
    private class ProblemHandler implements ProblemCreatedListener {
103

  
104
        private int id;
105

  
106
        public ProblemHandler() {
107
        }
108

  
109
        @Override
110
        public void handleNewProblem(EarliestArrivalProblem problem) {
111
            Verbose.println("NEW PROBLEM CREATED, agents:" + problem.nAgents());
112
            saveToFile(problem);
113
            id++;
114
        }
115

  
116
        private void saveToFile(EarliestArrivalProblem problem) {
117
            int nAgents = problem.nAgents();
118
            String fileName = String.format("A%03d_P%d_D%d_S%d_ID%d_%s", nAgents, patternNumber, step, seed, id, outputFile);
119

  
120
            if (!fileName.endsWith(".xml"))
121
                fileName = fileName + ".xml";
122

  
123
            try {
124
                FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));
125
                EarliestArrivalProblemXMLSerializer.serialize(problem, fileOutputStream);
126
            } catch (FileNotFoundException e) {
127
                System.err.println("!ERR! Could not write to file: " + fileName);
128
            }
129
        }
130
    }
131

  
132 89
    public static void main(String[] args) throws ProblemNotCreatedException, FileNotFoundException {
133 90

  
134 91
        String environmentFile = Args.getArgumentValue(args, "-env", true);
......
139 96
        String patternNumberStr = Args.getArgumentValue(args, "-gridpattern", false);
140 97
        if (patternNumberStr != null)
141 98
            patternNumber = Integer.parseInt(patternNumberStr);
142

  
99
        
143 100
        int step = 0;
144 101
        String stepStr = Args.getArgumentValue(args, "-gridstep", false);
102

  
145 103
        if (stepStr != null)
146 104
            step = Integer.parseInt(stepStr);
147 105

  
148 106
        int seed = Integer.parseInt(Args.getArgumentValue(args, "-seed", true));
149 107

  
150 108
        String outFile = Args.getArgumentValue(args, "-outfile", false);
109
        boolean showVis = Args.isArgumentSet(args, "-showvis");
151 110

  
152 111

  
153 112
        Rectangle missionArea = null;
......
161 120
            );
162 121
        }
163 122

  
164
        GenerateInstance main = new GenerateInstance(environmentFile, agents, radius, patternNumber, step, seed, missionArea);
123
        EarliestArrivalProblem instance = GenerateInstance.generateInstance(environmentFile, agents, radius, patternNumber, step, seed, missionArea);
165 124

  
166 125
        PrintStream outStream = System.out;
167 126

  
168 127
        if (outFile != null) {
169
            outStream = new PrintStream(new File(outFile));
128
        	outStream = new PrintStream(new File(outFile));
170 129
        }
171 130

  
172
        main.run(outStream);
131
        if (showVis) {
132
        	VisUtil.initVisualization(instance, "Generated Instance", 10);
133
        	VisUtil.visualizeProblem(instance);
134
        	VisUtil.visualizeGraph(instance.getPlanningGraph(), null);
135
        }
136

  
137
        EarliestArrivalProblemXMLSerializer.serialize(instance, outStream);
138

  
139

  
140

  
173 141
    }
174 142
}
src/main/java/tt/jointeuclid2ni/probleminstance/generator/TriangulationGenerator.java
70 70
        Collection<Region> inflatedObstacles = new LinkedList<Region>();
71 71
        inflatedObstacles.addAll(Util.inflateRegions(obstacles, bodyRadius));
72 72

  
73
        Collection<Region> customGraphPoints = new LinkedList<Region>(); 
73
        Collection<Region> customGraphPoints = new LinkedList<Region>();
74 74
        customGraphPoints.addAll(Util.inflateRegions(obstacles, bodyRadius+1));
75 75
        customGraphPoints.addAll(Util.inflateRegions(Collections.singleton(boundaryRegion), bodyRadius+1));
76 76

  
77

  
78

  
79 77
        DirectedGraph<Point, Line> planningGraph = Util.buildGridBasedRoadmap(inflatedObstacles, customGraphPoints, new Union(boundaryRegionDeflatedFlipped), dispersion, connectionRadius, Collections.<Point> emptyList());
80 78

  
81 79
        if (showVis) {
src/main/java/tt/jointeuclid2ni/sipprrts/SippRRTDemo.java
47 47
    private static final int SPEED = 4;
48 48
    private static final int SEED = 331;
49 49
    private static final int ENV_SIZE = 1000;
50
    private static final int OBSTACLE_COUNT = 0;
50
    private static final int OBSTACLE_COUNT = 10;
51 51
    private static final int OBSTACLES_SIZE = 200;
52 52
    private static final int MAX_RADIUS = 2 * ENV_SIZE;
53 53
    private static final int MIN_RADIUS = 100;

Also available in: Unified diff