public void cheapestFirePathTest() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 10); world.AddWay(2, 3, 5); world.AddWay(4, 3, 5); world.SetFire(1, 2); world.SetFire(4, 3); var paths = world.findCheapestFirePaths(2).ToArray(); if (paths.Count() != 2) { Assert.Fail(); } var path1 = paths[0]; var path2 = paths[1]; var resPath1 = new TravelPath(); resPath1.Add(1, 10); var resPath2 = new TravelPath(); resPath2.Add(3, 5); resPath2.Add(4, 5); Assert.IsTrue( path1.Equals(resPath1) && path2.Equals(resPath2) || path1.Equals(resPath2) && path2.Equals(resPath1)); }
public void cheapestWaterPathWithFire() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 10); world.AddWay(2, 3, 1); world.AddWay(4, 3, 1); world.PutWater(1, 4); world.SetFire(2, 3); world.SetFire(4, 3); var paths = world.findCheapestWaterPaths(2); if (paths.Count() != 1) { Assert.Fail(); } var path = paths.First(); var resPath = new TravelPath(); resPath.Add(1, 10); Assert.AreEqual(path, resPath); }
public void canWalkwithFire() { Human agent = new Human(1); world.PutWater(1); world.SetFire(1, 2); bool res = agent.pickupWater(world); bool res2 = agent.drive(world, 2); Assert.IsTrue(res == true && res2 == true); Assert.AreEqual(agent.TotalCost, 2 * world.getCostWay(1, 2) + agent.costs.Pickup); }
public void stuck1() { world.SetFire(1, 2); Pyromaniac agent = new Pyromaniac(1, 1); for (int i = 0; i < 20; i++) { double lastCost = agent.TotalCost; (agent.GetNextAction(world)).Invoke(world); Assert.AreEqual(agent.CurrentLocation, 1); } Assert.AreEqual(agent.TotalCost, agent.costs.Epsilon * 20); }
public void clearWays() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 2, 1); world.AddWay(1, 3, 1); world.AddWay(3, 2, 1); world.SetFire(1, 3); world.SetFire(2, 3); var ways = world.GetClearWays(1); Assert.AreEqual(ways.Count(), 1); Assert.IsFalse(!world.isClear(ways.First())); }
public void TestMethod1() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4, 5, 6, 7, 8, 9); world.AddWay(1, 2, 1); world.AddWay(3, 2, 1); world.AddWay(3, 9, 1); world.AddWay(8, 9, 10); world.AddWay(8, 7, 10); world.AddWay(6, 7, 10); world.AddWay(6, 5, 10); world.AddWay(4, 5, 10); world.AddWay(4, 1, 10); world.SetFire(1, 2); world.PutWater(2); var agents = new List <BaseAgent <bool, TravelWorld> >(); Simulator <TravelWorld, bool> sim = new Simulator <TravelWorld, bool>(world, new FireFighter(3), new Greedy(1, 3)); Console.SetOut(new StreamWriter("run.txt")); sim.Run(50); }
public void stopFire() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 2, 2); world.AddWay(3, 2, 2); world.AddWay(3, 1, 10); world.SetFire(2, 3); world.PutWater(2); FireFighter agent = new FireFighter(1); //go to the place with water (agent.GetNextAction(world))(world); Assert.AreEqual(agent.CurrentLocation, 2); Assert.AreEqual(agent.TotalCost, 2); double lastCost = agent.TotalCost; //PickWater (agent.GetNextAction(world)).Invoke(world); Assert.AreEqual(agent.CurrentLocation, 2); Assert.AreEqual(agent.TotalCost - lastCost, Costs.Instance.Pickup); Assert.IsFalse(world.HaveWater(2)); lastCost = agent.TotalCost; //stop fire (agent.GetNextAction(world))(world); Assert.AreEqual(agent.CurrentLocation, 3); Assert.AreEqual(agent.TotalCost - lastCost, 2 * world.getCostWay(2, 3)); Assert.IsFalse(agent.CarryWater); Assert.IsTrue(world.isClear(2, 3)); }
public void notFollwingOrgPath() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 1); world.AddWay(3, 2, 1); world.AddWay(3, 4, 1); world.AddWay(2, 4, 100); world.PutWater(1); world.SetFire(3, 4); world.PickupCost = 1; int goal = 4; //the path should be 2->1->2->3->4 RealTimeAStarAgent agnet = new RealTimeAStarAgent(new OneFireHuristic(goal).Run, 2, goal, 3); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(1, agnet.CurrentLocation); world.StopFire(3, 4); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(2, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(3, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(4, agnet.CurrentLocation); }
public void MainUristicCheckAstar() { //create a world where the least cost is to pickup water and go throgh a fire TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 1); world.AddWay(3, 2, 1); world.AddWay(3, 4, 1); world.AddWay(2, 4, 100); world.PutWater(1); world.SetFire(3, 4); world.PickupCost = 1; int goal = 4; //the path should be 2->1->pickup->2->3->4 RealTimeAStarAgent agnet = new RealTimeAStarAgent(new OneFireHuristic(goal).Run, 2, goal, 3); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(1, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(1, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(2, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(3, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(4, agnet.CurrentLocation); }
public void FireTest() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2); world.AddWay(1, 2, 1); world.SetFire(1, 2); Assert.IsFalse(world.isClear(1, 2)); }
public void SetFireTest() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 3, 1); world.SetFire(1, 3); world.StopFire(1, 3); Assert.IsTrue(world.isClear(1, 3)); }
public void NoClearWays() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 3, 1); world.SetFire(1, 3); var ways = world.GetClearWays(1); Assert.IsTrue(ways.Count() == 0); }
public TravelWorld ToWorld() { var world = new TravelWorld(WorldGraph); world.PutWater(WaterPlaces.ToArray()); foreach (var fireWay in FireWays) { world.SetFire(fireWay.Source, fireWay.Target); } return(world); }
private static TravelWorld CommonWorld() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 2, 10); world.AddWay(1, 3, 1); world.AddWay(3, 2, 10); world.SetFire(3, 1); world.PutWater(1); return(world); }
public void noWater() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 2, 2); world.AddWay(3, 2, 2); world.SetFire(1, 2); FireFighter agent = new FireFighter(1); (agent.GetNextAction(world)).Invoke(world); Assert.AreEqual(agent.CurrentLocation, 1); Assert.AreEqual(agent.TotalCost, agent.costs.Epsilon); }
public void noOperation(BaseTraveler agent) { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 1); world.AddWay(3, 2, 1); world.AddWay(3, 4, 1); world.SetFire(1, 2); double prevCost = agent.TotalCost; (agent.GetNextAction(world)).Invoke(world); Assert.AreEqual(agent.TotalCost - prevCost, Costs.Instance.Epsilon); Assert.AreEqual(agent.CurrentLocation, 2); }
public TravelWorld ToWorld() { var world = new TravelWorld(WorldGraph); world.PutWater(WaterPlaces.ToArray()); foreach (var fireWay in FireWays) { world.SetFire(fireWay.Source, fireWay.Target); } foreach (var item in locations) { world.SetLocation(item.Key, item.Value); } return(world); }
public void ClearPathTest() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4, 5); for (int i = 1; i <= 4; i++) { world.AddWay(i, i + 1, 1); } world.AddWay(5, 1, 1); world.SetFire(1, 2); var path = world.ShortestClearPath(1, 3); var resPath = new TravelPath(); resPath.Add(5, 1); resPath.Add(4, 1); resPath.Add(3, 1); Assert.IsTrue(resPath.Equals(path)); }
public void cheapestFirePathTest2() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 10); world.AddWay(2, 3, 5); world.AddWay(4, 3, 5); world.SetFire(1, 2); var paths = world.findCheapestFirePaths(2).ToArray(); if (paths.Count() != 1) { Assert.Fail(); } var path1 = paths.First(); var resPath1 = new TravelPath(); resPath1.Add(1, 10); Assert.AreEqual(path1, resPath1); }
public void NaturalGame() { TravelWorld world = new TravelWorld(); world.AddPlaces(2, 3, 4); world.AddWay(3, 2, 2); world.AddWay(3, 4, 2); world.AddWay(2, 4, 10); world.SetFire(2, 4); Human human = new Human(2); human.costs.Fire = 1; human.costs.Pickup = 5; human.Goal = 4; BasicCuttof cuttOf = new BasicCuttof(); agent = new NeutralAgent(2, 4, human, 3, 10); agent.costs.Fire = 10; agent.costs.Pickup = 5; world.AddPlayer(human); world.AddPlayer(agent); //eval.SetParams(agent, human, 10); cuttOf.SetParams(agent, 3); agent.GetNextAction(world)(world); Assert.AreEqual(3, agent.CurrentLocation); Assert.IsTrue(world.isClear(2, 3)); agent.GetNextAction(world)(world); Assert.AreEqual(4, agent.CurrentLocation); Assert.IsTrue(world.isClear(4, 3)); }
public void goToLowerPlaceTest() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 10); world.AddWay(3, 2, 1); world.AddWay(3, 4, 1); world.AddWay(2, 4, 10); GreedySearchAgent agent = new GreedySearchAgent(goToLowerPlace, 4); var action = agent.GetNextAction(world); //check if the world is the same before doing an action Assert.AreEqual(world.GetGraph().VertexCount, 4); Assert.AreEqual(world.GetGraph().EdgeCount, 4); //go to 2 Assert.IsTrue(action(world)); Assert.AreEqual(agent.CurrentLocation, 2); Assert.AreEqual(agent.TotalCost, world.getCostWay(4, 2)); double prevCost = agent.TotalCost; //go to 1 action = agent.GetNextAction(world); Assert.IsTrue(action(world)); Assert.AreEqual(agent.CurrentLocation, 1); Assert.AreEqual(agent.TotalCost, prevCost + world.getCostWay(1, 2)); prevCost = agent.TotalCost; world.SetFire(1, 2); //do nothing action = agent.GetNextAction(world); Assert.IsTrue(action(world)); Assert.AreEqual(agent.CurrentLocation, 1); Assert.AreEqual(agent.TotalCost, prevCost + world.EpsilonCost); }
public void MainUristicCheck() { //create a world where the least cost is to pickup water and go throgh a fire TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3, 4); world.AddWay(1, 2, 1); world.AddWay(1, 3, 1); world.AddWay(3, 2, 1); world.AddWay(3, 4, 1); world.PutWater(1); world.SetFire(1, 2); world.PickupCost = 10; int goal = 4; //the path should be 1->3->4 GreedySearchAgent agnet = new GreedySearchAgent(new OneFireHuristic(goal).Run, 1); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(3, agnet.CurrentLocation); Assert.IsTrue(agnet.GetNextAction(world)(world)); Assert.AreEqual(4, agnet.CurrentLocation); }