示例#1
0
 public DemandsVector(Scenario demands, PathAllocator pathAllocator)
 {
     _unicastDemands = CreateUnicastDemands(demands, pathAllocator);
     _anycastDemands = CreateAnycastDemands(demands, pathAllocator);
     _demands        = _unicastDemands;
     _demands.AddRange(_anycastDemands);
 }
示例#2
0
        public List <Demand> CreateUnicastDemands(Scenario demands, PathAllocator pathAllocator)
        {
            List <Demand> unicastDemands = new List <Demand>();
            Dictionary <int, UnicastDemandData> demandsData = demands.UnicastDemands.GetUnicastDemandDataDictionary();

            foreach (var key in demandsData)
            {
                UnicastDemand u = new UnicastDemand(key.Value.SourceNode, key.Value.DestinationNode,
                                                    key.Value.DemandVolume,
                                                    pathAllocator.GetCandidatePaths(key.Value.SourceNode, key.Value.DestinationNode));
                unicastDemands.Add(u);
            }

            return(unicastDemands);
        }
        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);
        }
示例#4
0
        public List <Demand> CreateAnycastDemands(Scenario demands, PathAllocator pathAllocator)
        {
            List <Demand> anycastDemands = new List <Demand>();
            List <int>    dataCenters    = new List <int>(demands.DataCenters.DataCenterNodes.ToList());
            Dictionary <int, AnycastDemandData> demandsData = demands.AnycastDemands.GetAnycastDemandDataDictionary();

            foreach (var key in demandsData)
            {
                var dict = new Dictionary <int, List <List <Path> > >();
                foreach (var d in dataCenters)
                {
                    var pathsUp   = new List <Path>(pathAllocator.GetCandidatePaths(key.Value.ClientNode, d));
                    var pathsDown = new List <Path>(pathAllocator.GetCandidatePaths(d, key.Value.ClientNode));
                    var paths     = new List <List <Path> >();
                    paths.Add(pathsUp);
                    paths.Add(pathsDown);
                    dict.Add(d, paths);
                }
                AnycastDemand a = new AnycastDemand(key.Value.ClientNode, key.Value.DownstreamVolume,
                                                    key.Value.UpstreamVolume, dataCenters, dict);
                anycastDemands.Add(a);
            }
            return(anycastDemands);
        }
示例#5
0
        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);
        }