Ejemplo n.º 1
0
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static HamiltonianCycleProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.HCP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider        = extractor.MakeNodeProvider();
            var nodes               = nodeProvider.GetNodes();
            var edgeProvider        = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = new NodeAdjacencyBasedWeightProvider(edgeProvider, 1, 2);
            var fixedEdgesProvider  = extractor.MakeFixedEdgesProvider(nodes);

            return(new HamiltonianCycleProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider));
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static TravelingSalesmanProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.TSP && tspFile.Type != FileType.ATSP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider        = extractor.MakeNodeProvider();
            var nodes               = nodeProvider.GetNodes();
            var edgeProvider        = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider  = extractor.MakeFixedEdgesProvider(nodes);
            var type = (tspFile.Type == FileType.TSP) ? ProblemType.TSP : ProblemType.ATSP;

            return(new TravelingSalesmanProblem(tspFile.Name, tspFile.Comment, type, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider));
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static CapacitatedVehicleRoutingProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.CVRP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider        = extractor.MakeNodeProvider();
            var nodes               = nodeProvider.GetNodes();
            var edgeProvider        = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider  = extractor.MakeFixedEdgesProvider(nodes);
            var depots              = extractor.MakeDepotsProvider(nodes);
            var demand              = extractor.MakeDemandProvider(nodes);

            return(new CapacitatedVehicleRoutingProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider, depots, demand));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static SequentialOrderingProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.SOP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            double weight = tspFile.EdgeWeights[0];

            tspFile.EdgeWeights.RemoveAt(0);

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider        = extractor.MakeNodeProvider();
            var nodes               = nodeProvider.GetNodes();
            var edgeProvider        = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider  = extractor.MakeFixedEdgesProvider(nodes);

            tspFile.EdgeWeights.Insert(0, weight);

            return(new SequentialOrderingProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider));
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static CapacitatedVehicleRoutingProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.CVRP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider = extractor.MakeNodeProvider();
            var nodes = nodeProvider.GetNodes();
            var edgeProvider = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider = extractor.MakeFixedEdgesProvider(nodes);
            var depots = extractor.MakeDepotsProvider(nodes);
            var demand = extractor.MakeDemandProvider(nodes);
            return new CapacitatedVehicleRoutingProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider, depots, demand);
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static SequentialOrderingProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.SOP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            double weight = tspFile.EdgeWeights[0];
            tspFile.EdgeWeights.RemoveAt(0);

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider = extractor.MakeNodeProvider();
            var nodes = nodeProvider.GetNodes();
            var edgeProvider = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider = extractor.MakeFixedEdgesProvider(nodes);

            tspFile.EdgeWeights.Insert(0, weight);

            return new SequentialOrderingProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider);
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static HamiltonianCycleProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.HCP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider = extractor.MakeNodeProvider();
            var nodes = nodeProvider.GetNodes();
            var edgeProvider = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = new NodeAdjacencyBasedWeightProvider(edgeProvider, 1, 2);
            var fixedEdgesProvider = extractor.MakeFixedEdgesProvider(nodes);
            return new HamiltonianCycleProblem(tspFile.Name, tspFile.Comment, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider);
        }
        /// <summary>
        /// Load problem from TSP file
        /// </summary>
        /// <param name="tspFile">TSP file instance</param>
        /// <returns>Loaded problem</returns>
        private static TravelingSalesmanProblem FromTspFile(TspFile tspFile)
        {
            if (tspFile.Type != FileType.TSP && tspFile.Type != FileType.ATSP)
            {
                throw new ArgumentOutOfRangeException("tspFile");
            }

            TspFileDataExtractor extractor = new TspFileDataExtractor(tspFile);
            var nodeProvider = extractor.MakeNodeProvider();
            var nodes = nodeProvider.GetNodes();
            var edgeProvider = extractor.MakeEdgeProvider(nodes);
            var edgeWeightsProvider = extractor.MakeEdgeWeightsProvider();
            var fixedEdgesProvider = extractor.MakeFixedEdgesProvider(nodes);
            var type = (tspFile.Type == FileType.TSP) ? ProblemType.TSP : ProblemType.ATSP;
            return new TravelingSalesmanProblem(tspFile.Name, tspFile.Comment, type, nodeProvider, edgeProvider, edgeWeightsProvider, fixedEdgesProvider);
        }