-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExampleProgram.cs
More file actions
206 lines (189 loc) · 10.1 KB
/
ExampleProgram.cs
File metadata and controls
206 lines (189 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Copyright 2024 MAES
//
// This file is part of MAES
//
// MAES is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// MAES is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with MAES. If not, see http://www.gnu.org/licenses/.
//
// Contributors: Rasmus Borrisholt Schmidt, Andreas Sebastian Sørensen, Thor Beregaard, Malte Z. Andreasen, Philip I. Holler and Magnus K. Jensen,
//
// Original repository: https://github.com/Molitany/MAES
using System;
using Maes.ExplorationAlgorithm.Minotaur;
using System.Collections;
using Maes.ExplorationAlgorithm.TheNextFrontier;
using Maes.Map;
using Maes.Map.MapGen;
using Maes.Robot;
using Maes.Utilities.Files;
using UnityEngine;
using Maes.Robot;
using Maes.ExplorationAlgorithm.Movement;
using System.Collections.Generic;
using Maes.UI;
using UnityEditor;
using System.Linq;
using Maes.ExplorationAlgorithm.Greed;
namespace Maes
{
internal class ExampleProgram : MonoBehaviour
{
private Simulator _simulator;
/*
*/
private void Start()
{
const int randomSeed = 12345;
var constraintsDict = new Dictionary<string, RobotConstraints>();
//var constraintsGlobalCommunication = new RobotConstraints(
constraintsDict["Global"] = new RobotConstraints(
senseNearbyAgentsRange: 5f,
senseNearbyAgentsBlockedByWalls: true,
automaticallyUpdateSlam: true,
slamUpdateIntervalInTicks: 1,
slamSynchronizeIntervalInTicks: 10,
slamPositionInaccuracy: 0.2f,
distributeSlam: false,
environmentTagReadRange: 4.0f,
slamRayTraceRange: 7f,
relativeMoveSpeed: 1f,
agentRelativeSize: 0.6f,
calculateSignalTransmissionProbability: (distanceTravelled, distanceThroughWalls) =>
{
return true;
}
);
//var constraintsMaterials = new RobotConstraints(
constraintsDict["Material"] = new RobotConstraints(
senseNearbyAgentsRange: 5f,
senseNearbyAgentsBlockedByWalls: true,
automaticallyUpdateSlam: true,
slamUpdateIntervalInTicks: 1,
slamSynchronizeIntervalInTicks: 10,
slamPositionInaccuracy: 0.2f,
distributeSlam: false,
environmentTagReadRange: 4.0f,
slamRayTraceRange: 7f,
relativeMoveSpeed: 1f,
agentRelativeSize: 0.6f,
materialCommunication: true
);
//var constraintsLOS = new RobotConstraints(
constraintsDict["LOS"] = new RobotConstraints(
senseNearbyAgentsRange: 5f,
senseNearbyAgentsBlockedByWalls: true,
automaticallyUpdateSlam: true,
slamUpdateIntervalInTicks: 1,
slamSynchronizeIntervalInTicks: 10,
slamPositionInaccuracy: 0.2f,
distributeSlam: false,
environmentTagReadRange: 4.0f,
slamRayTraceRange: 7f,
relativeMoveSpeed: 1f,
agentRelativeSize: 0.6f,
calculateSignalTransmissionProbability: (distanceTravelled, distanceThroughWalls) =>
{
// Blocked by walls
if (distanceThroughWalls > 0)
{
return false;
}
return true;
}
);
var simulator = Simulator.GetInstance();
var random = new System.Random(1234);
List<int> rand_numbers = new List<int>();
for (int i = 0; i < 100; i++)
{
var val = random.Next(0, 1000000);
rand_numbers.Add(val);
}
var constraintName = "Global";
var robotConstraints = constraintsDict[constraintName];
var buildingConfigList50 = new List<BuildingMapConfig>();
var buildingConfigList75 = new List<BuildingMapConfig>();
var buildingConfigList100 = new List<BuildingMapConfig>();
foreach (int val in rand_numbers)
{
buildingConfigList50.Add(new BuildingMapConfig(val, widthInTiles: 50, heightInTiles: 50));
buildingConfigList75.Add(new BuildingMapConfig(val, widthInTiles: 75, heightInTiles: 75));
buildingConfigList100.Add(new BuildingMapConfig(val, widthInTiles: 100, heightInTiles: 100));
}
var constraintIterator = 0;
var mapSizes = new List<int> { 50, 75, 100 };
var algorithms = new Dictionary<string, RobotSpawner.CreateAlgorithmDelegate>
{
{ "tnf", seed => new TnfExplorationAlgorithm(1, 10, seed) },
{ "minotaur", seed => new MinotaurAlgorithm(robotConstraints, seed, 2) },
{ "greed", seed => new GreedAlgorithm() }
};
constraintIterator++;
var buildingMaps = buildingConfigList50.Union(buildingConfigList75.Union(buildingConfigList100));
foreach (var mapConfig in buildingMaps)
{
for (var amountOfRobots = 1; amountOfRobots < 10; amountOfRobots += 2)
{
var robotCount = amountOfRobots;
foreach (var size in mapSizes)
{
foreach (var (algorithmName, algorithm) in algorithms)
{
simulator.EnqueueScenario(new SimulationScenario(seed: 123,
mapSpawner: generator => generator.GenerateMap(mapConfig),
robotSpawner: (buildingConfig, spawner) => spawner.SpawnRobotsTogether(
buildingConfig,
seed: 123,
numberOfRobots: robotCount,
suggestedStartingPoint: new Vector2Int(random.Next(0, size), random.Next(0, size)),
createAlgorithmDelegate: algorithm),
statisticsFileName: $"{algorithmName}-seed-{mapConfig.RandomSeed}-size-{size}-comms-{constraintName}-robots-{robotCount}-SpawnTogether",
robotConstraints: robotConstraints)
);
var spawningPosList = new List<Vector2Int>();
for (var amountOfSpawns = 0; amountOfSpawns < robotCount; amountOfSpawns++)
{
spawningPosList.Add(new Vector2Int(random.Next(0, size), random.Next(0, size)));
}
simulator.EnqueueScenario(new SimulationScenario(seed: 123,
mapSpawner: generator => generator.GenerateMap(mapConfig),
robotSpawner: (buildingConfig, spawner) => spawner.SpawnRobotsAtPositions(
collisionMap: buildingConfig,
seed: 123,
numberOfRobots: robotCount,
spawnPositions: spawningPosList,
createAlgorithmDelegate: algorithm),
statisticsFileName: $"{algorithmName}-seed-{mapConfig.RandomSeed}-size-{size}-comms-{constraintName}-robots-{robotCount}-SpawnApart",
robotConstraints: robotConstraints)
);
}
}
}
}
//Just code to make sure we don't get too many maps of the last one in the experiment
var dumpMap = new BuildingMapConfig(-1, widthInTiles: 50, heightInTiles: 50);
simulator.EnqueueScenario(new SimulationScenario(seed: 123,
mapSpawner: generator => generator.GenerateMap(dumpMap),
robotSpawner: (buildingConfig, spawner) => spawner.SpawnRobotsTogether(
buildingConfig,
seed: 123,
numberOfRobots: 5,
suggestedStartingPoint: Vector2Int.zero,
createAlgorithmDelegate: (seed) => new MinotaurAlgorithm(robotConstraints, seed, 2)),
statisticsFileName: $"delete-me",
robotConstraints: robotConstraints));
simulator.PressPlayButton(); // Instantly enter play mode
//simulator.GetSimulationManager().AttemptSetPlayState(SimulationPlayState.FastAsPossible);
}
}
}