protected void allocateDemands(DemandsVector demands) { _allocator.Erase(); foreach (var d in demands.Demands) { d.AllocateDemand(_allocator); } }
protected DemandsVector createInitialSolution(DemandsVector demands) { DemandsVector initialSolution = new DemandsVector(demands); foreach (var d in initialSolution.Demands) { d.SetRandomPath(); } initialSolution.Demands.Shuffle(); return(initialSolution); }
protected DemandsVector createNextSolution(DemandsVector currentSolution) { Random rnd = new Random(); DemandsVector nextSolution = new DemandsVector(currentSolution); int firstIndex = rnd.Next(0, nextSolution.Demands.Count); int lastIndex = rnd.Next(0, nextSolution.Demands.Count); nextSolution.Demands.Swap(firstIndex, lastIndex); nextSolution.Demands[lastIndex].SetRandomPath(); nextSolution.Demands[firstIndex].SetRandomPath(); return(nextSolution); }
public double Start() { _allocator = new SpectrumPathAllocator(_topologyGraph.Edges); int iterations = 0; var timer = new Stopwatch(); double timeStart = 0.0; timer.Start(); Random rnd = new Random(); PathAllocator pathAllocator = new PathAllocator(_scenario, _topologyGraph.NumberOfNodes); DemandsVector currentSolution = new DemandsVector(_scenario, pathAllocator); currentSolution = createInitialSolution(currentSolution); allocateDemands(currentSolution); _currentFitness = _topologyGraph.ComputeCost(); timer.Stop(); _scenario.ObjectiveFunctionResult = _bestFitness; _scenario.ElapsedAlgorithmTime = timer.ElapsedMilliseconds; return(timer.ElapsedMilliseconds); }
public double Start(double initialTemperature, double alpha, double finalTemperature, Scenario scenario) { _initialTemperature = initialTemperature; _currentTemperature = initialTemperature; _alpha = alpha; _finalTemperature = finalTemperature; _scenario = scenario; _bestEnergy = 0; _currentEnergy = 0; _nextEnergy = 0; _topologyGraph = new Graph(_scenario); _allocator = new SpectrumPathAllocator(_topologyGraph.Edges); int iterations = 0; var timer = new Stopwatch(); double timeStart = 0.0; timer.Start(); Random rnd = new Random(); PathAllocator pathAllocator = new PathAllocator(_scenario, _topologyGraph.NumberOfNodes); DemandsVector currentSolution = new DemandsVector(_scenario, pathAllocator); currentSolution = createInitialSolution(currentSolution); allocateDemands(currentSolution); _currentEnergy = _topologyGraph.ComputeCost(); int initialEnergy = _currentEnergy; DemandsVector bestSolution = new DemandsVector(currentSolution); _bestEnergy = _currentEnergy; while (_currentTemperature > _finalTemperature) { DemandsVector nextSolution = new DemandsVector(createNextSolution(currentSolution)); allocateDemands(nextSolution); _nextEnergy = _topologyGraph.ComputeCost(); if (_nextEnergy < _currentEnergy) { _currentEnergy = _nextEnergy; currentSolution = new DemandsVector(nextSolution); if (_nextEnergy < _bestEnergy) { _bestEnergy = _nextEnergy; bestSolution = new DemandsVector(nextSolution); } } else if (computeProbablity() > rnd.NextDouble()) //this returns a value in range (0.0, 0.1) by default with no arguments { _currentEnergy = _nextEnergy; currentSolution = new DemandsVector(nextSolution); } _currentTemperature = _currentTemperature * _alpha; iterations++; if (iterations > 10000) { _currentTemperature = 0.0; } } timer.Stop(); _scenario.ObjectiveFunctionResult = _bestEnergy; _scenario.ElapsedAlgorithmTime = timer.ElapsedMilliseconds; return(timer.ElapsedMilliseconds); }
public DemandsVector(DemandsVector v) { _demands = new List <Demand>(v._demands); }