Skip to content

Commit

Permalink
Merge branch 'main' into robot-controller-eta-method
Browse files Browse the repository at this point in the history
  • Loading branch information
henneboy authored Nov 18, 2024
2 parents f0d8948 + 6f7c416 commit 09bc5b0
Show file tree
Hide file tree
Showing 101 changed files with 1,350 additions and 567 deletions.
57 changes: 50 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,38 @@ on:

### Refer to https://game.ci/docs/github/getting-started
jobs:
setup:
name: Setup Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Cache .NET tools
uses: actions/cache@v3
with:
path: |
~/.nuget/packages
~/.dotnet/tools
key: dotnet-tools-${{ runner.os }}-8.0
restore-keys: |
dotnet-tools-${{ runner.os }}
- name: Cache Packages
uses: actions/cache@v3
with:
path: Assets/Packages
key: Packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install NuGetForUnity.Cli
run: dotnet tool install --global NuGetForUnity.Cli
- name: Restore NuGet Packages for Unity Project
run: nugetforunity restore .

test:
needs: setup
permissions:
checks: write
name: Run all tests ✨
Expand All @@ -22,6 +53,10 @@ jobs:
with:
path: Library
key: Library-test
- uses: actions/cache/restore@v3
with:
path: Assets/Packages
key: Packages
- uses: game-ci/unity-test-runner@v4
id: testRunner
env:
Expand All @@ -39,7 +74,7 @@ jobs:


build:
needs: test
needs: [setup, test]
name: Build for ${{ matrix.targetPlatform }}
runs-on: ubuntu-latest
strategy:
Expand All @@ -57,6 +92,10 @@ jobs:
with:
path: Library
key: Library-${{ matrix.targetPlatform }}
- uses: actions/cache/restore@v3
with:
path: Assets/Packages
key: Packages
- uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
Expand All @@ -76,6 +115,16 @@ jobs:
container: unityci/editor:ubuntu-2022.3.51f1-linux-il2cpp-3.1.0
steps:
- uses: actions/checkout@v1
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install NuGetForUnity.Cli
run: |
dotnet tool install --global NuGetForUnity.Cli
echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
- name: Restore NuGet Packages for Unity Project
run: nugetforunity restore .
- name: Generate Solution
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
Expand All @@ -85,11 +134,5 @@ jobs:
run: |
unity-editor -nographics -logFile /dev/stdout -quit -username "$UNITY_EMAIL" -password "$UNITY_PASSWORD" -serial "$UNITY_SERIAL"
unity-editor -nographics -logFile /dev/stdout -customBuildName LinuxProjectFileBuild -projectPath . -executeMethod Packages.Rider.Editor.RiderScriptEditor.SyncSolution -quit
- name: Print the files in the folder
run: ls
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Format
run: dotnet format MAEPS.sln --exclude "Assets/RosMessages/" --exclude "Assets/YamlDotNet/" --verify-no-changes
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ InitTestScene*
/maes-csv-reader/datasets
/maes-csv-reader/src/__pycache*
.DS_Store
/Assets/Packages
Assets/Packages.meta
19 changes: 19 additions & 0 deletions Assets/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources />
<packageSourceCredentials />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<config>
<add key="packageInstallLocation" value="CustomWithinAssets" />
<add key="repositoryPath" value="./Packages" />
<add key="PackagesConfigDirectoryPath" value="." />
<add key="slimRestore" value="true" />
<add key="ReadOnlyPackageFiles" value="true" />
<add key="PreferNetStandardOverNetFramework" value="true" />
</config>
</configuration>
23 changes: 23 additions & 0 deletions Assets/NuGet.config.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions Assets/PlayModeTests/ExplorationCsvDataWriterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

using Maes.Robot;
using Maes.Simulation;
using Maes.Simulation.SimulationScenarios;
using Maes.Statistics.Exploration;

using NUnit.Framework;

namespace PlayModeTests
{
public class ExplorationCsvDataWriterTest
{
private ExplorationSimulator _maes;
private ExplorationSimulation _explorationSimulation;
private const string Delimiter = ",";
private readonly CultureInfo _culture = CultureInfo.InvariantCulture;
private const int RandomSeed = 123;
private static readonly string Directory = Path.Join("data", "test", $"{RandomSeed}ExplorationCsvDataWriterTestFolder");

[SetUp]
public void SetUp()
{
InitSimulator();
if (!System.IO.Directory.Exists(Directory))
{
System.IO.Directory.CreateDirectory(Directory);
}

}

[TearDown]
public void TearDown()
{
_maes.Destroy();
if (System.IO.Directory.Exists(Directory))
{
System.IO.Directory.Delete(Directory, true);
}
}

private void InitSimulator()
{
var testingScenario = new ExplorationSimulationScenario(RandomSeed,
mapSpawner: StandardTestingConfiguration.EmptyCaveMapSpawner(RandomSeed),
hasFinishedSim: _ => false,
robotConstraints: new RobotConstraints(),
robotSpawner: (map, spawner) => spawner.SpawnRobotsInBiggestRoom(map, RandomSeed, 2,
_ => new TestingAlgorithm()
));

_maes = new ExplorationSimulator();
_maes.EnqueueScenario(testingScenario);
_explorationSimulation = _maes.SimulationManager.CurrentSimulation;
}

[Test]
public void ExplorationSnapshotToCsvTest()
{
_explorationSimulation.ExplorationTracker.snapShots.Add(new ExplorationSnapShot(1, 0.1f, 0.1f, 1f));
_explorationSimulation.ExplorationTracker.snapShots.Add(new ExplorationSnapShot(2, 0.2f, 0.2f, 5f));
_explorationSimulation.ExplorationTracker.snapShots.Add(new ExplorationSnapShot(3, 0.5f, 0.3f, 10f));
_explorationSimulation.ExplorationTracker.snapShots.Add(new ExplorationSnapShot(4, 0.7f, 0.4f, 10f));
_explorationSimulation.ExplorationTracker.snapShots.Add(new ExplorationSnapShot(5, 0.9f, 0.5f, 5f));

_explorationSimulation.CommunicationManager.CommunicationTracker.InterconnectionSnapShot.Add(1, true);
_explorationSimulation.CommunicationManager.CommunicationTracker.InterconnectionSnapShot.Add(3, false);
_explorationSimulation.CommunicationManager.CommunicationTracker.InterconnectionSnapShot.Add(4, true);

_explorationSimulation.CommunicationManager.CommunicationTracker.BiggestClusterPercentageSnapshots.Add(1, 5f);
_explorationSimulation.CommunicationManager.CommunicationTracker.BiggestClusterPercentageSnapshots.Add(2, 10f);
_explorationSimulation.CommunicationManager.CommunicationTracker.BiggestClusterPercentageSnapshots.Add(5, 12f);

var expectedExplorationSnapShots = new List<ExplorationSnapShot>
{
new(1, 0.1f, 0.1f, 1f, true, 5f),
new(2, 0.2f, 0.2f, 5f, null, 10f),
new(3, 0.5f, 0.3f, 10f, false),
new(4, 0.7f, 0.4f, 10f, true),
new(5, 0.9f, 0.5f, 5f, null, 12f)
};

var filename = Path.Join(Directory, $"ExplorationSnapshotToCsvTest{DateTime.Now.Ticks}");
var writer = new ExplorationCsvDataWriter(_explorationSimulation, filename);
writer.CreateCsvFile(Delimiter);

var lines = File.ReadAllLines(filename + ".csv");
Assert.AreEqual(expectedExplorationSnapShots.Count, lines.Length - 1); // -1 because of header
for (var i = 0; i < expectedExplorationSnapShots.Count; i++)
{
var line = lines[i + 1]; // +1 because of header
var values = line.Split(Delimiter);
var expected = expectedExplorationSnapShots[i];

Assert.AreEqual(expected.Tick.ToString(), values[0]);
Assert.AreEqual(expected.Explored.ToString(_culture), values[1]);
Assert.AreEqual(expected.Covered.ToString(_culture), values[2]);
Assert.AreEqual(expected.AverageAgentDistance.ToString(_culture), values[3]);

if (expected.AgentsInterconnected == null)
{
Assert.AreEqual("", values[4]);
}
else
{
var expectedValue = expected.AgentsInterconnected.Value ? "1" : "0";
Assert.AreEqual(expectedValue, values[4]);
}

Assert.AreEqual(
expected.BiggestClusterPercentage == null ? "" : expected.BiggestClusterPercentage.ToString(),
values[5]);
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/PlayModeTests/ExplorationCsvDataWriterTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Resources/Patrolling_MAEPS.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -3982,7 +3982,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 5767229281082634687}
m_HandleRect: {fileID: 2761231736617164433}
m_Direction: 0
m_Value: 1
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
Expand Down Expand Up @@ -4471,7 +4471,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: ToggleIdleGraph
m_Text: Toggle Idle Graph
--- !u!1 &2221302390552499367
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1228844,7 +1228844,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 5271981897940419086}
m_HandleRect: {fileID: 2971747523843396219}
m_Direction: 2
m_Value: 1
m_Value: 1.0000001
m_Size: 0.522
m_NumberOfSteps: 0
m_OnValueChanged:
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Algorithms/IPatrollingAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace Maes.Algorithms
{
public delegate void OnReachVertex(Vertex vertex, int atTick);
public delegate void OnReachVertex(int vertexId, int atTick);

public interface IPatrollingAlgorithm : IAlgorithm
{
string AlgorithmName { get; }

Vertex TargetVertex { get; }

void SetPatrollingMap(PatrollingMap map);

void SubscribeOnReachVertex(OnReachVertex onReachVertex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;

using Maes.Algorithms;
using Maes.Map;

namespace Maes.ExplorationAlgorithm.Minotaur
{
Expand All @@ -48,7 +49,7 @@ public IMinotaurMessage Combine(IMinotaurMessage otherMessage, MinotaurAlgorithm
if (_winnerList.Contains(minotaur._controller.GetRobotID()))
{
minotaur._controller.StopCurrentTask();
minotaur._waypoint = new Waypoint(minotaur._map.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.NearestDoor, true);
minotaur._waypoint = new Waypoint(CoarseGrainedMap.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.NearestDoor, true);
minotaur._controller.PathAndMoveTo(minotaur._waypoint.Value.Destination);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Linq;

using Maes.Algorithms;
using Maes.Map;

namespace Maes.ExplorationAlgorithm.Minotaur
{
Expand Down Expand Up @@ -76,14 +77,14 @@ public IMinotaurMessage Process(MinotaurAlgorithm minotaur)
{
winnerIDList.Add(key);
}
minotaur._waypoint = new Waypoint(minotaur._map.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.Door, true);
minotaur._waypoint = new Waypoint(CoarseGrainedMap.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.Door, true);
minotaur._controller.PathAndMoveTo(minotaur._waypoint.Value.Destination);
minotaur._doorways.Find(x => x.Center == _doorway.Center).Explored = true;
return new AuctionResultMessage(winnerIDList, _doorway);
}
else if (_allBids.Count / 2 == 1)
{
minotaur._waypoint = new Waypoint(minotaur._map.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.Door, true);
minotaur._waypoint = new Waypoint(CoarseGrainedMap.FromSlamMapCoordinate(_doorway.Center + _doorway.ExitDirection.Vector * 4), Waypoint.WaypointType.Door, true);
minotaur._controller.PathAndMoveTo(minotaur._waypoint.Value.Destination);
minotaur._doorways.Find(x => x.Center == _doorway.Center).Explored = true;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;

using Maes.Algorithms;
using Maes.Map;

namespace Maes.ExplorationAlgorithm.Minotaur
{
Expand Down Expand Up @@ -50,13 +51,13 @@ public IMinotaurMessage Combine(IMinotaurMessage otherMessage, MinotaurAlgorithm
/// </summary>
public IMinotaurMessage? Process(MinotaurAlgorithm minotaur)
{
var doorwayTile = minotaur._map.FromSlamMapCoordinate(_doorway.Center);
var doorwayTile = CoarseGrainedMap.FromSlamMapCoordinate(_doorway.Center);
var pathLengthToDoorway = minotaur._map.GetPath(doorwayTile, false, false);
if (pathLengthToDoorway != null)
{
foreach (var knownDoorway in minotaur._doorways)
{
if (pathLengthToDoorway.Contains(minotaur._map.FromSlamMapCoordinate(knownDoorway.Center)))
if (pathLengthToDoorway.Contains(CoarseGrainedMap.FromSlamMapCoordinate(knownDoorway.Center)))
{
return null;
}
Expand Down
Loading

0 comments on commit 09bc5b0

Please sign in to comment.