Example #1
0
        private void CalculateSwitchCosts()
        {
            int rooms = model.modelRooms.Count;

            //Parallel.For(0, rooms, index => {
            for (int index = 0; index < rooms; index++)
            {
                for (int secondindex = index + 1; secondindex < rooms; secondindex++)
                {
                    //Parallel.For(index + 1, rooms, secondindex => {
                    MyRoom r1        = model.modelRooms.ElementAt(index);
                    MyRoom r2        = model.modelRooms.ElementAt(secondindex);
                    MyRoom r1target  = null;
                    MyRoom r2target  = null;
                    Model  tempModel = model.DeepCopy(r1, r2, out r1target, out r2target);
                    tempModel.SwitchRooms(ref r1target, ref r2target);
                    if (!tempModel.IsInInvalidState)
                    {
                        double cost = CostCalculationService.CalculateCost(tempModel).First();
                        lock (locker) {
                            Actions.Add(new Switch(ref r1, ref r2, cost));
                        }
                    }
                    //});
                }
            }
            //});
        }
Example #2
0
        public void SwitchRoom(ref MyRoom r1, ref MyRoom r2)
        {
            Action a = new Switch(ref r1, ref r2);

            a.Step(model);
            double[] costs = CostCalculationService.CalculateCost(model);

            actualCost       = costs[0];
            actualAreaCost   = costs[1];
            actualLayoutCost = costs[2];
            HandleModelChangeUpdate();
        }
Example #3
0
        public void Move(MyLine lineGridSelectedItem, int movedistance)
        {
            Action a = new Move(lineGridSelectedItem, movedistance);

            a.Step(model);
            double[] costs = CostCalculationService.CalculateCost(model);

            actualCost       = costs[0];
            actualAreaCost   = costs[1];
            actualLayoutCost = costs[2];
            HandleModelChangeUpdate();
        }
Example #4
0
        public void Split(int splitPercentage, MyLine lineGridSelectedItem)
        {
            Action a = new Split(splitPercentage, lineGridSelectedItem);

            a.Step(model);
            double[] costs = CostCalculationService.CalculateCost(model);

            actualCost       = costs[0];
            actualAreaCost   = costs[1];
            actualLayoutCost = costs[2];
            HandleModelChangeUpdate();
        }
Example #5
0
        private void CalculateMoveCosts()
        {
            //Parallel.For(0, model.modelLines.Count,
            //    index => {
            for (int index = 0; index < model.modelLines.Count; index++)
            {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model  tempModel = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(moveDistance, newMyLine);
                if (tempModel.IsInInvalidState)
                {
                    continue;
                }

                double[] costs      = CostCalculationService.CalculateCost(tempModel);
                double   summary    = costs[0];
                double   areacost   = costs[1];
                double   layoutcost = costs[2];
                lock (locker) {
                    Actions.Add(new Move(myLine, summary, areacost, layoutcost, moveDistance));
                }
            }
            //});
            //Parallel.For(0, model.modelLines.Count,
            //    index => {
            for (int index = 0; index < model.modelLines.Count; index++)
            {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model  tempModel = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(-moveDistance, newMyLine);
                if (tempModel.IsInInvalidState)
                {
                    continue;
                }
                double[] costs      = CostCalculationService.CalculateCost(tempModel);
                double   summary    = costs[0];
                double   areacost   = costs[1];
                double   layoutcost = costs[2];
                lock (locker) {
                    Actions.Add(new Move(myLine, summary, areacost, layoutcost, -moveDistance));
                }
            }
            //});
        }
Example #6
0
        public void run()
        {
            Stopwatch st = new Stopwatch();

            st.Start();
            while (true && !isFinished && !isTimeout && !isTreshold && !IsStopped)
            {
                Actions.Clear();
                SaveState();
                actualCost = CostCalculationService.CalculateCost(model).ElementAt(0);
                CalculateCostsForState();
                MakeAStepByTheCalculatedCosts();
                HandleModelChangeUpdate();
                Thread.Sleep(5);
                actualSimulationIndex++;
                if (actualSimulationIndex > MaxSimulationIndex)
                {
                    isFinished = true;
                }
                if (st.ElapsedMilliseconds > 60000)
                {
                    isTimeout = true;
                }
                if (actualSimulationThreshold >= MaxSimulationThreshold)
                {
                    isTreshold = true;
                }
            }

            Logger.WriteLog($"Run Ended.\nFinished: {isFinished}\nTimeout: {isTimeout}\nTreshold: {isTreshold}\nStopped manually: {IsStopped}");
            //actualSimulationIndex = 0;
            actualSimulationThreshold = 0;
            isFinished          = false;
            isTimeout           = false;
            isTreshold          = false;
            IsStopped           = false;
            MaxSimulationIndex += MaxSimulationIndex;
        }