public TspOptimizerBase(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
 {
     _startPermutation = startPermutation;
     _euclideanPath    = euclideanPath;
     _config           = config;
     _optimalSequence  = new Subject <int[]>();
     _closedPath       = true;
     OptimizerInfo     = new Subject <string>();
 }
Exemplo n.º 2
0
        /// <summary>
        ///  Factory to create specified optimizer
        /// </summary>
        /// <param name="tspOptimizerAlgorithm"></param>
        /// <param name="startSequence"></param>
        /// <param name="euclideanPath"></param>
        /// <returns></returns>
        public static ITspOptimizer Create(TspOptimizerAlgorithm tspOptimizerAlgorithm,
                                           int[] startSequence, IEuclideanPath euclideanPath,
                                           OptimizerConfig config)
        {
            ITspOptimizer tspOptimizer = null;

            switch (tspOptimizerAlgorithm)
            {
            case TspOptimizerAlgorithm.RandomOptimizer:
                tspOptimizer = new RandomOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.LocalCombinationOptimizer:
                tspOptimizer = new LocalCombinationOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.MultiLocalCombinationOptimizer:
                tspOptimizer = new MultiLocalCombinationOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.LocalTwoOptOptimizer:
                tspOptimizer = new LocalTwoOptOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.BruteForceOptimizer:
                tspOptimizer = new BruteForceOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.BranchAndBoundOptimizer:
                tspOptimizer = new BranchAndBoundOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.SimulatedAnnealingOptimizer:
                tspOptimizer = new SimulatedAnnealingOptimizer(startSequence, euclideanPath, config);
                break;

            case TspOptimizerAlgorithm.GeneticOptimizer:
                tspOptimizer = new GeneticOptimizer(startSequence, euclideanPath, config);
                break;

            default:
                throw new ArgumentException("Unknown optimizer");
            }

            return(tspOptimizer);
        }
Exemplo n.º 3
0
        public GeneticOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
            : base(startPermutation, euclideanPath, config)
        {
            _rate       = _config.CrossoverRate;
            _number     = _startPermutation.Length;
            _population = _config.PopulationSize;
            _random     = new Random();
            _partiallyMappedCrossover = new PartiallyMappedCrossover(_number);

            MinDistance = double.MaxValue;
        }
 public GridLocalOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     // ToDo: Get from config
     _maxCellCount = 16;
     _points       = euclideanPath.Points;
 }
Exemplo n.º 5
0
 public SimulatedAnnealingOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     _coolingRate = _config.CoolingRate;
 }
Exemplo n.º 6
0
 public LocalCombinationOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
 }
Exemplo n.º 7
0
 public BruteForceOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     _permutationCount = Enumerable.Range(1, _startPermutation.Length).Aggregate(1, (acc, val) => acc * val);
 }
 public RandomOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
 }
Exemplo n.º 9
0
 public MultiLocalCombinationOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     _globalMinimum = double.MaxValue;
     SetMultiSearcher(_config.NumberOfCores);
 }
 public LocalTwoOptOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     OptimalSequence         = _startPermutation.ToArray();
     _downSampledOptSequence = new Subject <int[]>();
     _disposeStream          = Observable.Interval(TimeSpan.FromMilliseconds(100))
                               .ObserveOn(Scheduler.Default)
                               .CombineWithLatest(_downSampledOptSequence, (time, seq) => seq)
                               .Subscribe(seq => _optimalSequence.OnNext(seq));
 }
 public BranchAndBoundOptimizer(int[] startPermutation, IEuclideanPath euclideanPath, OptimizerConfig config)
     : base(startPermutation, euclideanPath, config)
 {
     _minPathLength = double.MaxValue;
 }