Esempio n. 1
0
        public MyLine GetNormal(bool isNormalized = false)
        {
            //if we define dx = x2 - x1 and dy = y2 - y1, then the normals are(-dy, dx) and(dy, -dx).
            double dx          = StartMyPoint.X - EndMyPoint.X;
            double dy          = StartMyPoint.Y - EndMyPoint.Y;
            MyLine normaMyLine = new MyLine(new MyPoint(-dy, dx), new MyPoint(dy, -dx));

            if (!isNormalized)
            {
                return(normaMyLine);
            }
            else
            {
                return(Normalize(normaMyLine));
            }
        }
Esempio n. 2
0
        private void SimulationStep()
        {
            int moveDistance = int.Parse(this.textBox2.Text);

            //Dictionary<MyLine, double> Costs = new Dictionary<MyLine, double>();
            double mincost = 100000;
            MyLine minline = null;

            //make threadpool like - room pool
            //fix number of modells, (number of threads) move elemnet, calculate cost

            //https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-write-a-simple-parallel-foreach-loop

            double actualCost = model.CalculateCost().First();

            foreach (MyLine line in model.modelLines)
            {
                MyLine newMyLine;
                Model  tempModel = model.DeepCopy(line, out newMyLine);
                tempModel.MoveLine(moveDistance, newMyLine);

                double cost = tempModel.CalculateCost().First();
                //Costs.Add(myLine, cost);

                if (mincost > cost)
                {
                    mincost = cost;
                    minline = line;
                }
            }

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

            //model.MoveLine(moveDistance, model.GetRandomLine());
            model.MoveLine(moveDistance, minline);
        }