Esempio n. 1
0
            public void CalculateNode()
            {
                lock (edgeLocker)
                {
                    if (IsCalculated)
                    {
                        return;
                    }

                    List <double[]> inSchedule, outSchedule,
                                    inFixValues  = AH.CreateListOfArrays(start.algorithm._period, start.algorithm._inDimension, -1.0),
                                    outFixValues = AH.CreateListOfArrays(start.algorithm._period, start.algorithm._outDimension, -1.0);

                    for (int i = 0; i < start.crashIndex - 1; i++)
                    {
                        inFixValues[i]  = start.inSchedule[i].Select(x => x).ToArray();
                        outFixValues[i] = start.outSchedule[i].Select(x => x).ToArray();
                    }
                    for (int i = start.crashIndex - 1; i < workTime; i++)
                    {
                        inFixValues[i]  = regimesPair.Item1.Select(x => x).ToArray();
                        outFixValues[i] = regimesPair.Item2.Select(x => x).ToArray();
                    }

                    inSchedule  = start.algorithm._inAlgorithm.GetSchedule(start.initVals.inTargets, inFixValues);
                    outSchedule = start.algorithm._outAlgorithm.GetSchedule(start.initVals.outTargets, outFixValues);

                    end           = new GreedyNode(inSchedule, outSchedule, start.algorithm, start.initVals);
                    end.inputEdge = this;

                    IsCalculated = true;
                }
            }
Esempio n. 2
0
        public Tuple <List <double[]>, List <double[]> > FormSchedule(ref InitialValues initVals, Action <string> action = null)
        {
            List <double[]> inFixValues  = AH.CreateListOfArrays(_period, _inDimension, -1.0),
                            outFixValues = AH.CreateListOfArrays(_period, _outDimension, -1.0),
                            inSchedule   = _inAlgorithm.GetSchedule(initVals.inTargets, inFixValues),
                            outSchedule  = _outAlgorithm.GetSchedule(initVals.outTargets, outFixValues);

            DiscreteSchedule reservoirSchedule = GetReservoirSchedule(inSchedule, outSchedule, initVals.startVolume, initVals.pumpsSchedule);
            int idx = reservoirSchedule.FirstIndexOfOutOfRange(initVals.minVolume, initVals.maxVolume);

            if (idx == -1)
            {
                return(new Tuple <List <double[]>, List <double[]> >(inSchedule, outSchedule));
            }

            List <Tuple <List <double[]>, List <double[]> > > schedules;

            switch (initVals.algorithmType)
            {
            case AlgorithmType.GRAPH:
                schedules = GreedyRandomizeSearch(ref initVals, inSchedule, outSchedule, action);
                break;

            default:
                schedules = new List <Tuple <List <double[]>, List <double[]> > >()
                {
                    DinamicProgramming(initVals, action)
                };
                break;
            }

            action("Выбираем оптимальное на основе критериев");

            if (schedules.Count() == 0)
            {
                return(null);
            }
            else if (schedules.Count() == 1)
            {
                return(schedules[0]);
            }
            else
            {
                List <double> criterias = GetCriteria(initVals.inTargets, initVals.outTargets, schedules);
                var           best      = schedules[criterias.IndexOf(criterias.Min())];
                return(best);
            }
        }