Пример #1
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++;
        }
Пример #2
0
        private void Paint()
        {
            AutoScrollCosts();
            isPainting = true;
            //LoadDataFromModel();
            testcanvas.Children.Clear();
            //DrawAxis(testcanvas);

            Logger.WriteLog("paint started");
            for (var i = 0; i < model.modelLines.Count; i++)
            {
                MyLine    line            = model.modelLines[i];
                ShapeLine myLine          = new ShapeLine();
                Brush     solidColorBrush = new SolidColorBrush(Color.FromArgb(95, 0, 0, 0));
                solidColorBrush.Opacity = 0.5;
                if (i.Equals(selectedLineIndex))
                {
                    solidColorBrush = Brushes.Yellow;
                }

                myLine.Stroke             = solidColorBrush;
                myLine.X1                 = line.StartMyPoint.X;
                myLine.X2                 = line.EndMyPoint.X;
                myLine.Y1                 = line.StartMyPoint.Y;
                myLine.Y2                 = line.EndMyPoint.Y;
                myLine.StrokeEndLineCap   = PenLineCap.Triangle;
                myLine.StrokeStartLineCap = PenLineCap.Round;
                myLine.StrokeThickness    = 10;
                myLine.ToolTip            = line.ToString();
                testcanvas.Children.Add(myLine);
            }

            for (var i = 0; i < model.ModelPoints.Count; i++)
            {
                MyPoint   point  = model.ModelPoints[i];
                ShapeLine myLine = new ShapeLine();

                var solidColorBrush = new SolidColorBrush(Color.FromArgb(90, 255, 0, 0));
                solidColorBrush.Opacity = 0.5;
                if (i.Equals(selectedPointIndex))
                {
                    solidColorBrush = Brushes.GreenYellow;
                }

                myLine.Stroke             = solidColorBrush;
                myLine.X1                 = point.X;
                myLine.X2                 = point.X + 1;
                myLine.Y1                 = point.Y;
                myLine.Y2                 = point.Y + 1;
                myLine.StrokeStartLineCap = PenLineCap.Round;
                myLine.StrokeEndLineCap   = PenLineCap.Triangle;
                myLine.StrokeThickness    = 10;
                myLine.ToolTip            = point.ToString();
                testcanvas.Children.Add(myLine);
            }

            //foreach (MyRoom room in model.modelRooms) {
            foreach (MyRoom room in Rooms)
            {
                List <MyPoint> boundaries = room.GetBoundaryPointsSorted();
                if (!boundaries.Any())
                {
                    continue;
                }
                //boundaries.RemoveAll(item => item == null); //this is error handling, but I would need to figure out why nulls exist
                List <Point> convertedPoints = boundaries.Select(i => new Point(i.X, i.Y)).ToList();
                Polygon      p = new Polygon();
                p.Points  = new PointCollection(convertedPoints);
                p.Fill    = new SolidColorBrush(room.type.fillColor.ToMediaColor());
                p.Opacity = 0.25;
                p.ToolTip = room.ToString();
                testcanvas.Children.Add(p);
            }

            isPainting = false;
        }
Пример #3
0
 public LineAndCost(MyLine l, double d, int i)
 {
     line  = l.ToString();
     cost  = d;
     index = i;
 }