public async Task ATest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\a_example.in")); var solution = new Solution(problem.NumberOfCars); var state = new CityState(problem.Cars.ToImmutableList(), new RidesView3(problem.Rides, problem.Bonus), 0); var tree = GrainFactory.GetGrain <ITreeGrain <MakeRideAction> >(Guid.NewGuid()); await tree.Init(state); await tree.Build(); INodeView <MakeRideAction> node; while ((node = await tree.GetTopAction()) != null) { Trace.WriteLine(node.Action); if (!node.Action.Car.Equals(Car.SkipRide)) { solution.CarActions[node.Action.Car.Id].Add(node.Action); } await tree.ContinueFrom(node.Id); await tree.Build(); } Assert.NotNull(solution); Trace.WriteLine("Finished"); Trace.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Trace.WriteLine(solution.ToString()); Assert.Equal(10, solution.GetTotalScore(problem.Bonus)); }
private static async Task DoClientWork(IClusterClient client) { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\Resources\a_example.in")); var solution = new Solution(problem.NumberOfCars); var state = new CityState(problem.Cars.ToImmutableList(), new RidesView3(problem.Rides, problem.Bonus), 0); var tree = client.GetGrain <ITreeGrain <MakeRideAction> >(Guid.NewGuid()); tree.Init(state).Wait(); tree.Build().Wait(); INodeView <MakeRideAction> node; // while ((node = tree.GetTopAction().Result) != null) // { // if (!node.Action.Car.Equals(Car.SkipRide)) // { // solution.CarActions[node.Action.Car.Id].Add(node.Action); // } // // tree.ContinueFrom(node.Id).Wait(); // tree.Build().Wait(); // } Console.WriteLine("Finished"); Console.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Console.WriteLine(solution.ToString()); }
static void Main(string[] args) { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\a_example.in")); var solution = CityProblemSolver.Solve(problem); Console.WriteLine($"a: {solution.GetTotalScore(problem.Bonus).ToString()}"); File.WriteAllText(@"..\..\..\Resources\a_example.out", solution.ToString()); problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); solution = CityProblemSolver.Solve(problem); Console.WriteLine($"b: {solution.GetTotalScore(problem.Bonus).ToString()}"); File.WriteAllText(@"..\..\..\Resources\b_should_be_easy.out", solution.ToString()); problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\c_no_hurry.in")); solution = CityProblemSolver.Solve(problem); Console.WriteLine($"c: {solution.GetTotalScore(problem.Bonus).ToString()}"); File.WriteAllText(@"..\..\..\Resources\c_no_hurry.out", solution.ToString()); problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\d_metropolis.in")); solution = CityProblemSolver.Solve(problem); Console.WriteLine($"d: {solution.GetTotalScore(problem.Bonus).ToString()}"); File.WriteAllText(@"..\..\..\Resources\d_metropolis.out", solution.ToString()); problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\e_high_bonus.in")); solution = CityProblemSolver.Solve(problem); Console.WriteLine($"e: {solution.GetTotalScore(problem.Bonus).ToString()}"); File.WriteAllText(@"..\..\..\Resources\e_high_bonus.out", solution.ToString()); }
public void GetTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); var sut = new RidesView(problem.Rides); var actual = sut.GetRides(); Trace.WriteLine(sut.GetEarliestFinish()); }
public void CBuildTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\c_no_hurry.in")); var graph = Graph.Build(problem.Rides); Assert.NotNull(graph); Assert.Equal(10000, graph.Vertices.Count); Trace.WriteLine(graph.Edges.Count); }
public void DTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\d_metropolis.in")); var solution = GreedyProblemSolver.Solve(problem); Assert.NotNull(solution); Trace.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Trace.WriteLine(solution.ToString()); }
public void CTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\c_no_hurry.in")); var solution = CityProblemSolver.Solve(problem); Assert.NotNull(solution); Trace.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Trace.WriteLine(solution.ToString()); }
public void BTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); var solution = IndependentSetProblemSolver.Solve(problem); Assert.NotNull(solution); Trace.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Trace.WriteLine($"Missed rides: {string.Join(" ", solution.GetMissedRides())}"); Trace.WriteLine(solution.ToString()); }
public void ATest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\a_example.in")); var solution = IndependentSetProblemSolver.Solve(problem); Assert.NotNull(solution); Trace.WriteLine("Finished"); Trace.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Trace.WriteLine(solution.ToString()); Assert.Equal(10, solution.GetTotalScore(problem.Bonus)); }
public async Task SiloSayHelloTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\a_example.in")); var state = new CityState(problem.Cars.ToImmutableList(), new RidesView3(problem.Rides, problem.Bonus), 0); var grain = GrainFactory.GetGrain <ITreeGrain <MakeRideAction> >(Guid.NewGuid()); await grain.Init(state); await grain.Build(); var bestNode = await grain.GetTopAction(); Assert.NotNull(bestNode); Trace.WriteLine(bestNode.Action); }
public void ABuildTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\a_example.in")); var graph = Graph.Build(problem.Rides); Assert.NotNull(graph); Assert.Equal(3, graph.Vertices.Count); foreach (var vertex in graph.Vertices) { Trace.WriteLine(vertex); } foreach (var edge in graph.Edges) { Trace.WriteLine(edge); } }
public void GetAvailableActionsTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); var availableRides = new HashSet <Ride>(); availableRides.Add(new Ride(0, new Point(), new Point(10, 10), 0, 110)); availableRides.Add(new Ride(1, new Point(1, 1), new Point(10, 10), 0, 110)); availableRides.Add(new Ride(2, new Point(2, 2), new Point(3, 3), 0, 110)); var sut = new CityCarState(problem, new Car(0, new Point(), 0), availableRides, 0); var actual = sut.GetAvailableActions(); foreach (var makeRideAction in actual) { Trace.WriteLine(makeRideAction); } }
public void GetAvailableActionsTest() { var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); var availableRides = new List <Ride> { new Ride(0, new Point(), new Point(10, 10), 0, 110), new Ride(1, new Point(1, 1), new Point(10, 10), 0, 110), new Ride(2, new Point(2, 2), new Point(3, 3), 0, 110) }; var cars = new List <Car> { new Car(0, new Point(), 0), new Car(1, new Point(), 0), }; var sut = new CityState(cars.ToImmutableList(), new RidesView3(availableRides, problem.Bonus), 0); var actual = sut.GetAvailableActions(); foreach (var makeRideAction in actual) { Trace.WriteLine(makeRideAction); } }
static void Main(string[] args) { Trace.Listeners.Add(new ConsoleTraceListener()); // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); siloConfig.Globals.ResponseTimeout = TimeSpan.FromMinutes(10); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); clientConfig.ResponseTimeout = TimeSpan.FromMinutes(10); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // var problem = ProblemBuilder.Build(File.ReadAllLines(@"..\..\..\Resources\b_should_be_easy.in")); var solution = new Solution(problem.NumberOfCars); var state = new CityState(problem.Cars.ToImmutableList(), new RidesView3(problem.Rides, problem.Bonus), 0); var tree = client.GetGrain <ITreeGrain <MakeRideAction> >(Guid.NewGuid()); tree.Init(state).Wait(); tree.Build().Wait(); var counter = 0; INodeView <MakeRideAction> node; while ((node = tree.GetTopAction().Result) != null) { //Trace.WriteLine(node.Action); if (!node.Action.Car.Equals(Car.SkipRide)) { solution.CarActions[node.Action.Car.Id].Add(node.Action); } if (counter++ % 20 == 0) { Trace.WriteLine($"Counter: {counter}"); Trace.WriteLine($"Current score: {solution.GetTotalScore(problem.Bonus).ToString()}"); } tree.ContinueFrom(node.Id).Wait(); tree.Build().Wait(); } Console.WriteLine("Finished"); Console.WriteLine(solution.GetTotalScore(problem.Bonus).ToString()); Console.WriteLine(solution.ToString()); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }