Exemple #1
0
        private void SimulationStepSwitch()
        {
            Dictionary <MyRoom, double> RoomCosts = new Dictionary <MyRoom, double>();

            double actualCost           = CostCalculationService.CalculateCost(model).First();
            double mincost              = actualCost;
            int    rooms                = model.modelRooms.Count;
            MyRoom switchThisMyRoomFrom = null;
            MyRoom switchThisMyRoomTo   = null;

            Parallel.For(0, rooms,
                         index => {
                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);

                    double cost = CostCalculationService.CalculateCost(tempModel).First();
                    lock (locker) {
                        RoomCosts.Add(r1, cost);
                        if (mincost >= cost)
                        {
                            mincost = cost;
                            //this might need to be switched later
                            switchThisMyRoomFrom = r1;
                            switchThisMyRoomTo   = r2;
                        }
                    }
                });
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }


            if (switchThisMyRoomFrom != null && switchThisMyRoomTo != null)
            {
                model.SwitchRooms(ref switchThisMyRoomFrom, ref switchThisMyRoomTo);
            }
            else
            {
                MessageBox.Show("no room to switch");
            }

            double[] costArray = CostCalculationService.CalculateCost(model);

            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));
            actualSimulationIndex++;
        }
Exemple #2
0
 private void ModelChangeHandler(object sender, ProgressEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(() => {
         lock (locker) {
             SaveStateToPng();
             model = e.model;
             SimulationCosts.Add(new Costs(e.simIndex, e.cost, e.areacost, e.layoutcost, 0, e.stepAction));
             LoadDataFromModel();
             Paint();
         }
     }), DispatcherPriority.SystemIdle);
 }
Exemple #3
0
 private void ModelChangeHandler(object sender, ProgressEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         lock (locker)
         {
             //SaveStateToPng();
             modelHistory.Add(model);
             model = e.model;
             SimulationCosts.Add(e.Cost);
             LoadDataFromModel();
             Paint();
         }
     }), DispatcherPriority.Normal); //changed from idle
 }
Exemple #4
0
        public void Draw()
        {
            double[] sum    = SimulationCosts.Select(i => i.SummaryCost).ToArray();
            double[] area   = SimulationCosts.Select(i => i.AreaCost).ToArray();
            double[] layout = SimulationCosts.Select(i => i.LayoutCost).ToArray();
            string[] index  = SimulationCosts.Select(i => i.Index.ToString()).ToArray();

            SeriesCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Title = "SummaryCosts",
                    //Values = new ChartValues<double> { 4, 6, 5, 2 ,4 }
                    Values = sum.AsChartValues()
                },
                new LineSeries
                {
                    Title = "AreaCosts",
                    //Values = new ChartValues<double> { 6, 7, 3, 4 ,6 },
                    Values        = area.AsChartValues(),
                    PointGeometry = null
                },
                new LineSeries
                {
                    Title = "LayoutCosts",
                    //Values = new ChartValues<double> { 4,2,7,2,7 },
                    Values            = layout.AsChartValues(),
                    PointGeometry     = DefaultGeometries.Square,
                    PointGeometrySize = 15
                }
            };

            //Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May" };
            Labels     = index;
            YFormatter = value => value.ToString("C");
        }
Exemple #5
0
        private void SimulationStepMove()
        {
            Dictionary <string, double> Costs = new Dictionary <string, double>();
            MyLine minline             = null;
            int    currentMoveDistance = moveDistance;
            double actualCost          = CostCalculationService.CalculateCost(model).First();
            double mincost             = actualCost;

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("+" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = moveDistance;
                    }
                }
            });

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(-moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("-" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = -moveDistance;
                    }
                }
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }
            if (minline != null)
            {
                model.MoveLine(currentMoveDistance, minline);
            }
            else
            {
                MessageBox.Show("no line to move");
            }
            LineAndCostActualStep.Clear();
            foreach (var item in Costs)
            {
                LineAndCostActualStep.Add(new LineAndCost(item.Key, item.Value, actualSimulationIndex));
            }
            //System.Windows.Forms.MessageBox.Show(mincost.ToString());
            //SimulationCosts.Add(new Costs(actualSimulationIndex, mincost));

            double[] costArray = CostCalculationService.CalculateCost(model);
            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));

            actualSimulationIndex++;
        }