Exemplo n.º 1
0
        public static void ResetSimulation()
        {
            var problemsPath = ProblemsFinder.FindProblemsFolderPath();

            problem = ProblemLoader.LoadProblem(Path.Combine(problemsPath, "prob-150.desc"), null);

            controller = new ScoreNActionsController(problem, new SmartIslandController(problem, null));
            //controller = new ScoreNActionsController(problem, new IslandFinderController(problem, new ScoreNActionsController(problem, new DijkstraController(problem))));
            //controller = new CachingScoreTurnActionsController(problem, new SmartIslandController(problem, null));
            //controller = new ScoreTurnActionsController(problem, new SmartIslandController(problem, null));
            //controller = new ScoreTurnActionsController(problem, new IslandFinderController(problem, new ScoreSingleActionsController(problem, new DijkstraController(problem))));
            //controller = new IslandFinderController(problem, new ScoreSingleActionsController(problem, new DijkstraController(problem)));
            //controller = new ScoreTurnActionsController(problem, new ScoreSingleActionsController(problem, new DijkstraController(problem)));
            start = false;
        }
Exemplo n.º 2
0
    void StartStage()
    {
        problem = ProblemLoader.LoadProblem();
        ProblemManager.Instance.SetProblem(problem);
        BeatManager.Instance.StartBeat();
        playLoopCoroutine = PlayLoop();
        StartCoroutine(playLoopCoroutine);

        ProblemManager.Instance.OnProblemFinish
        .Subscribe(_i => {
            StopCoroutine(playLoopCoroutine);
        });

        startStageSubject.OnNext(0);
    }
Exemplo n.º 3
0
        protected override string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems)
        {
            ///// Hey here is the problem to solve! (undivided, everything is in CommonData)
            string problem = Utilities.Base64Decode(solvePartialProblems.CommonData);

            globalProblem = problem;
            //solvePartialProblems.Id;
            NodeWorker worker = new NodeWorker(solvePartialProblems.Id);

            worker.problemObject = ProblemLoader.loadnewExampleString(globalProblem);
            Workers.Add(worker);
            double    sol       = worker.calculateAlgorithm();
            Solutions solutions = new Solutions();

            solutions.Id         = solvePartialProblems.Id;
            solutions.CommonData = Utilities.Base64Encode(sol.ToString());
            Console.WriteLine("How Long = " + this.Workers.First().HowLong);
            CMSocket.Instance.SendMessage(this.Port, this.IP, solutions.SerializeToXML(), this);
            return(null);
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            Arguments a = new Arguments();

            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();
            parser.ExtractArgumentAttributes(a);
            parser.ParseCommandLine(args);

            if (!Directory.Exists(a.ProblemsFolder))
            {
                throw new ArgumentException($"Problems folder {a.ProblemsFolder} does not exist");
            }

            if (!Directory.Exists(a.SolutionsFolder))
            {
                throw new ArgumentException($"Solutions folder {a.SolutionsFolder} does not exist");
            }

            if (!Directory.Exists(a.CacheFolder))
            {
                throw new ArgumentException($"Solutions folder {a.CacheFolder} does not exist");
            }

            var problems = Directory.GetFiles(a.ProblemsFolder, "*.desc");

            var existingSolutions = Directory.GetFiles(a.SolutionsFolder, "*.sol");

            Parallel.ForEach(problems, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, p =>
            {
                var problem = ProblemLoader.LoadProblem(p, a.CacheFolder);
                Console.WriteLine($"Working on {problem.Name}");

                var controller = new CachingScoreTurnActionsController(problem, new SmartIslandController(problem, null));
                //var controller = new ScoreTurnActionsController(problem, new IslandFinderController(problem, new ScoreSingleActionsController(problem, new DijkstraController(problem))));
                var done = false;

                do
                {
                    foreach (var robot in problem.Robots)
                    {
                        var actions = controller.GetNextActions(robot);
                        if (actions.Count() == 1 && actions.First() is RobotDoneAction)
                        {
                            var solutionFile = Path.Combine(a.SolutionsFolder, problem.Name + ".sol");
                            File.WriteAllText(solutionFile, problem.Solution);

                            Console.WriteLine($"Done with {problem.Name}");
                            done = true;
                            break;
                        }

                        if (!done)
                        {
                            problem.ProcessAction(robot, actions);
                        }
                    }

                    if (done)
                    {
                        break;
                    }
                } while (true);
            });
        }
Exemplo n.º 5
0
 public MpTutor(int problemIndex)
 {
     _pl = new ProblemLoader(problemIndex);
 }
Exemplo n.º 6
0
    static void Main(string[] args)
    {
        try
        {
            List <int>    LocationList        = new List <int>();
            List <double> DeliverDemandList   = new List <double>();
            List <int>    ServiceDurationList = new List <int>();
            List <int>    ServiceBeginList    = new List <int>();
            List <int>    ServiceEndList      = new List <int>();
            List <string> VehicleNameList     = new List <string>();
            List <double> VehicleCapacityList = new List <double>();
            List <int>    X_CoordinateList    = new List <int>();
            List <int>    Y_CoordinateList    = new List <int>();

            StreamReader InputFile = new System.IO.StreamReader(Directory.GetCurrentDirectory() + @"\d.txt");

            using (InputFile)
            {
                string InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                string[] InputData = InputLine.Split(' ');
                LocationList.Add(Convert.ToInt32(InputData[0]));

                InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                InputData = InputLine.Split(' ');
                for (int i = 0; i < InputData.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        LocationList.Add(Convert.ToInt32(InputData[i]));
                        VehicleNameList.Add(InputData[i]);
                    }
                    else
                    {
                        DeliverDemandList.Add(-Convert.ToDouble(InputData[i], CultureInfo.InvariantCulture));
                    }
                }


                InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                InputData = InputLine.Split(' ');
                for (int i = 0; i < InputData.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                    }
                    else if (i % 3 == 1)
                    {
                        X_CoordinateList.Add(Convert.ToInt32(InputData[i]));
                    }
                    else
                    {
                        Y_CoordinateList.Add(Convert.ToInt32(InputData[i]));
                    }
                }

                InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                InputData = InputLine.Split(' ');
                for (int i = 0; i < InputData.Length; i++)
                {
                    if (i % 2 != 0)
                    {
                        ServiceDurationList.Add(Convert.ToInt32(InputData[i]));
                    }
                }

                InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                InputData = InputLine.Split(' ');
                ServiceBeginList.Add(Convert.ToInt32(InputData[1]));
                ServiceEndList.Add(Convert.ToInt32(InputData[2]));
                int ServiceEndDepot = Convert.ToInt32(InputData[2]);
                InputLine = InputFile.ReadLine();
                InputLine = InputFile.ReadLine();

                InputData = InputLine.Split(' ');
                for (int i = 0; i < InputData.Length; i++)
                {
                    if (i % 2 != 0)
                    {
                        const double cutoff = 0.5;
                        if (Convert.ToInt32(InputData[i]) > ServiceEndDepot * cutoff)
                        {
                            ServiceBeginList.Add(0);
                        }
                        else
                        {
                            ServiceBeginList.Add(Convert.ToInt32(InputData[i]));
                        }
                        ServiceEndList.Add(ServiceEndDepot);
                        const double AllVehicleCapacity = 100;
                        VehicleCapacityList.Add(AllVehicleCapacity);
                    }
                }
            }

            int[]            Location        = LocationList.ToArray();        //ilosc lokacji, po prostu id
            double[]         DeliverDemand   = DeliverDemandList.ToArray();   //zawsze dodatnie demand
            int[]            ServiceDuration = ServiceDurationList.ToArray(); //stala 20
            int[]            ServiceBegin    = ServiceBeginList.ToArray();
            int[]            ServiceEnd      = ServiceEndList.ToArray();      //available
            string[]         VehicleName     = VehicleNameList.ToArray();     //depot end
            double[]         VehicleCapacity = VehicleCapacityList.ToArray(); //stala 100
            int[]            X_Coordinate    = X_CoordinateList.ToArray();    //wszystko
            int[]            Y_Coordinate    = Y_CoordinateList.ToArray();    //wszystko
            newExampleObject o = ProblemLoader.loadnewExample("problem16.vrp");

            //int[] Location = o.Location;
            //double[] DeliverDemand = o.DeliverDemand;
            //int[] ServiceDuration = o.ServiceDuration;
            //int[] ServiceBegin = o.ServiceBegin;
            //int[] ServiceEnd = o.ServiceEnd;
            //string[] VehicleName = o.VehicleName;
            //double[] VehicleCapacity = o.VehicleCapacity;
            //int[] X_Coordinate = o.X_Coordinate;
            //int[] Y_Coordinate = o.Y_Coordinate;


            Location        = o.Location;
            DeliverDemand   = o.DeliverDemand;
            ServiceDuration = o.ServiceDuration;
            ServiceBegin    = o.ServiceBegin;
            ServiceEnd      = o.ServiceEnd;
            VehicleName     = o.VehicleName;
            VehicleCapacity = o.VehicleCapacity;
            X_Coordinate    = o.X_Coordinate;
            Y_Coordinate    = o.Y_Coordinate;



            //double[,] DistanceMatrix = new double[Location.GetLength(0), Location.GetLength(0)];
            //double[,] DriveTimeMatrix = new double[Location.GetLength(0), Location.GetLength(0)];

            //for(int i=0;i<X_Coordinate.Length;i++)
            //{
            //    for(int j=i;j<X_Coordinate.Length;j++)
            //    {
            //        if(i==j)
            //        {
            //            DistanceMatrix[i,j] = 0;
            //            DriveTimeMatrix[i,j] = 0;

            //        }
            //        else
            //        {
            //            DistanceMatrix[i,j]=Math.Sqrt((X_Coordinate[i] - X_Coordinate[j])*(X_Coordinate[i] - X_Coordinate[j]) + (Y_Coordinate[i] - Y_Coordinate[j])*(Y_Coordinate[i] - Y_Coordinate[j]));
            //            DriveTimeMatrix[i,j] = DistanceMatrix[i,j];
            //            DistanceMatrix[j,i] = DistanceMatrix[i,j];
            //            DriveTimeMatrix[j,i] = DriveTimeMatrix[i,j];
            //        }

            //    }
            //}

            double[,] DistanceMatrix  = o.DistanceMatrix;
            double[,] DriveTimeMatrix = o.DriveTimeMatrix;


            Console.WriteLine("\n" + "Input data files have been successfully read.");

            AlgorithmSolution.Find_Solution(Location, DeliverDemand, ServiceBegin, ServiceEnd, ServiceDuration, DistanceMatrix, DriveTimeMatrix, VehicleName, VehicleCapacity);
        }

        catch (FormatException)
        {
            Console.WriteLine("\n" + "Sorry, You have not entered valid integer number.");
        }

        catch (FileNotFoundException FNFE)
        {
            Console.WriteLine(FNFE.Message);
        }

        catch (IOException IOE)
        {
            Console.WriteLine(IOE.Message);
        }

        Console.ReadKey(true);
        Console.ReadKey();
    }
Exemplo n.º 7
0
        public void TestProblemLoader()
        {
            var problemFile = Path.Join(ProblemsFolderPath, "prob-051.desc");

            var p = ProblemLoader.LoadProblem(problemFile, null);
        }