コード例 #1
0
ファイル: BinaryArgsConverter.cs プロジェクト: JFFby/OPR-Labs
 public EntityArgs Convert(SquarePoint point)
 {
     return new BinaryEntityArgs
     {
         X = point.x,
         Y = point.y
     };
 }
コード例 #2
0
ファイル: HyperCubeWrapper.cs プロジェクト: JFFby/OPR-Labs
 public IShlp GetShlpObject(SquarePoint point)
 {
     return new ShlpHyperCube(
       point,
       config.SideLength,
       config.DeltaSideLenth,
       config.IterationCount,
       config.InnerPointsCount,
       config.Bounds,
       config.Fn,
       config.IterationMode);
 }
コード例 #3
0
ファイル: Square.cs プロジェクト: JFFby/OPR-Labs
        public static Square GeneratePointsFromLeftCorner(SquarePoint startPoint, float sideLength, int innerpointsCount, SquarePoint[] bounds)
        {
            startPoint.Number = 1;
            var points = new List<SquarePoint> { startPoint };
            points.Add(new SquarePoint(startPoint.x, startPoint.y + sideLength, 2));
            points.Add(new SquarePoint(startPoint.x + sideLength, startPoint.y + sideLength, 3));
            points.Add(new SquarePoint(startPoint.x + sideLength, startPoint.y, 4));
            var square = new Square { BoundPoints = points };
            square.CreateInnerPoints(innerpointsCount, bounds);

            return square;
        }
コード例 #4
0
ファイル: NelderMid.cs プロジェクト: JFFby/OPR-Labs
 public NelderMid(
     MKT_Point startPoint,
     Func<float, float, float> fn,
     SquarePoint[] bounds,
     MktIterationMode iterationMode)
 {
     this.startPoint = startPoint;
     this.fn = fn;
     _points = new List<MKT_Point>();
     this.bounds = bounds;
     currentPoints = new MKT_Point[3];
     maxPoints = iterationMode == MktIterationMode.Full ? 75 : 6;
 }
コード例 #5
0
ファイル: HyperCubeWrapper.cs プロジェクト: JFFby/OPR-Labs
 public HyperCubeWrapper(Func<float,float,float> fn, SquarePoint[] bounds, MktIterationMode iterationMode)
 {
     this.config =  new ShlpHyperCubeConfig
     {
         Fn = fn,
         DeltaSideLenth = 1.1f,
         InnerPointsCount = 5,
         SideLength = 1,
         IterationCount = 15,
         Bounds = bounds,
         IterationMode = iterationMode
     };
 }
コード例 #6
0
ファイル: UnitTest1.cs プロジェクト: JFFby/OPR-Labs
 public void TestMethod1()
 {
     var startPoint = new SquarePoint(1, 1);
     var bounds = new[] { new SquarePoint(0, 0), new SquarePoint(4.2f, 6.4f), };
     var hc = new ShlpHyperCube(startPoint, 1, 1.1f, 15, 10, bounds, MultiplicationCoord, MktIterationMode.Limited);
     var nm = new NelderMid(new MKT_Point(startPoint.x, startPoint.y, MultiplicationCoord), MultiplicationCoord, bounds, MktIterationMode.Limited);
     var watch1 = Stopwatch.StartNew();
     var hsResult = hc.Calculate();
     watch1.Stop();
     var watch2 = Stopwatch.StartNew();
     var nmResult = nm.Calculate();
     watch2.Stop();
     var nm_r = MultiplicationCoord(nmResult.x, nmResult.y);
     var hs_r = MultiplicationCoord(hsResult.x, hsResult.y);
     Assert.IsTrue(Math.Abs(nm_r - hs_r) <1);
 }
コード例 #7
0
ファイル: HyperCube.cs プロジェクト: JFFby/OPR-Labs
 public HyperCube(
     SquarePoint startpoint,
     float sideLength,
     float deltaSideLenth,
     int iterationCount,
     int innerPointsCount,
     SquarePoint[] bounds,
     MktIterationMode iterationMode,
     bool isDebugMode = false)
 {
     this.deltaSideLength = deltaSideLenth;
     this.startPoint = startpoint;
     this.sideLength = sideLength;
     this.iterationCount = iterationMode == MktIterationMode.Full ? iterationCount : 2;
     this.innerPointsCount = innerPointsCount;
     this.isDebugMode = isDebugMode;
     this.bounds = bounds;
 }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: JFFby/OPR-Labs
 public void TestMethod2()
 {
     Expression<Func<float, float, float>> fn_exp = (x, y) => (float)(Math.Pow((y - Math.Pow(x, 2)), 2) + Math.Pow((1 - x), 2));
     var fn = fn_exp.Compile();
     var startPoint = new SquarePoint(1, 1);
     var bounds = new[] { new SquarePoint(0, 0), new SquarePoint(4.2f, 6.4f), };
     var hc = new ShlpHyperCube(startPoint, 1, 1.1f, 25, 10, bounds, fn, MktIterationMode.Limited);
     var nm = new NelderMid(new MKT_Point(startPoint.x, startPoint.y, fn), fn, bounds, MktIterationMode.Limited);
     var watch1 = Stopwatch.StartNew();
     var hsResult = hc.Calculate();
     watch1.Stop();
     var watch2 = Stopwatch.StartNew();
     var nmResult = nm.Calculate();
     watch2.Stop();
     var nm_r = fn(nmResult.x, nmResult.y);
     var hs_r = fn(hsResult.x, hsResult.y);
     Assert.IsTrue(Math.Abs(nm_r - hs_r) < 0.01);
 }
コード例 #9
0
ファイル: Square.cs プロジェクト: JFFby/OPR-Labs
 public void CreateInnerPoints(int innerpointsCount, SquarePoint[] bounds)
 {
     var points = new List<SquarePoint>();
     var point3 = this.BoundPoints.Single(x => x.Number == 3);
     var maxX = Math.Min(point3.x, bounds[1].x);
     var maxY = Math.Min(point3.y, bounds[1].y);
     var point1 = this.BoundPoints.Single(x => x.Number == 1);
     var minX = Math.Max(point1.x, bounds[0].x);
     var minY = Math.Max(point1.y, bounds[0].y);
     var rnd = new Random(DateTime.Now.GetHashCode());
     for (int i = 0; i < innerpointsCount; i++)
     {
         var rndX = minX + rnd.NextDouble() * (maxX - minX);
         var rndY = minY + rnd.NextDouble() * (maxY - minY);
         points.Add(new SquarePoint((float)rndX, (float)rndY, i));
     }
     InnerPoints = points;
 }
コード例 #10
0
ファイル: Shlp_HyperCube.cs プロジェクト: JFFby/OPR-Labs
 public ShlpHyperCube(
     SquarePoint startpoint,
     float sideLength,
     float deltaSideLenth,
     int iterationCount,
     int innerPointsCount,
     SquarePoint[] bounds,
     Func<float, float, float> fn,
     MktIterationMode iterationMode)
     : base(startpoint,
         sideLength,
         deltaSideLenth,
         iterationCount,
         innerPointsCount,
         bounds,
         iterationMode,
         false)
 {
     this.fn = fn;
 }
コード例 #11
0
ファイル: NelderMid.cs プロジェクト: JFFby/OPR-Labs
        private SquarePoint Iteration()
        {
            do
            {
                var isComressionNeeded = false;
                currentPoints = currentPoints.OrderByDescending(x => x.Value).ToArray();
                var xh = currentPoints[hi];
                var xg = currentPoints[gi];
                var xl = currentPoints[li];

                if (float.IsInfinity(xl.Value))
                {
                    break;
                }

                var xc = new SquarePoint(
                    (xg.x + xl.x) / 2,
                    (xg.y + xl.y) / 2);
                var xr = new MKT_Point(
                    Xr(xc.x, xh.x),
                    Xr(xc.y, xh.y),
                    fn);

                if (xr.Value < xl.Value)
                {
                    var xe = new MKT_Point(
                        Xe(xc.x, xr.x),
                        Xe(xc.y, xr.y),
                        fn);
                    if (xe.Value <= xr.Value)
                    {
                        SetupCurrentPoint(xe, hi);
                    }
                    else
                    {
                        SetupCurrentPoint(xr, hi);
                    }
                }
                else if (xl.Value < xr.Value && xr.Value < xh.Value)
                {
                    SetupCurrentPoint(xr, hi);
                }
                else if (xg.Value < xr.Value && xr.Value < xh.Value)
                {
                    var buf_xr = xr;
                    xr = xh;
                    xh = buf_xr;
                    isComressionNeeded = true;
                }
                else
                {
                    isComressionNeeded = true;
                }

                if (isComressionNeeded)
                {
                    var xs = new MKT_Point(Xs(xh.x, xc.x), Xs(xh.y, xc.y), fn);
                    if (xs.Value < xh.Value)
                    {
                        SetupCurrentPoint(xs, hi);
                    }
                    else
                    {
                        var xi_xh = new MKT_Point(Xi(xh.x, xl.x), Xi(xh.y, xl.y), fn);
                        SetupCurrentPoint(xi_xh, hi);
                        var xi_xg = new MKT_Point(Xi(xg.x, xl.x), Xi(xg.y, xl.y), fn);
                        SetupCurrentPoint(xi_xg, hi);
                    }
                }

            } while (OneMoreIteration());

            var suitablePoints =
                _points.Where(x => x.x <= bounds[1].x && x.x >= bounds[0].x && x.y >= bounds[0].y && x.y <= bounds[1].y);
            return suitablePoints
                .FirstOrDefault(x => Math.Abs(x.Value - suitablePoints.Min(c => c.Value)) < 0.01);
        }
コード例 #12
0
ファイル: NelderMidWrapper.cs プロジェクト: JFFby/OPR-Labs
 public IShlp GetShlpObject(SquarePoint point)
 {
     return new NelderMid((MKT_Point)point, fn, bounds, iterationMode);
 }
コード例 #13
0
ファイル: NelderMidWrapper.cs プロジェクト: JFFby/OPR-Labs
 public NelderMidWrapper(Func<float, float, float> fn, SquarePoint[] bounds, MktIterationMode iterationMode)
 {
     this.fn = fn;
     this.bounds = bounds;
     this.iterationMode = iterationMode;
 }
コード例 #14
0
ファイル: ShapeAnalizer.cs プロジェクト: ttohin/komorki
        void AnalizeInternalTriagle(Buffer <int> buffer, Square square, int x, int y, float moveVertextToCorner = 0.3f)
        {
            SquarePoint     startPoint = SquarePoint.Center;
            SquareBaseShape shape      = SquareBaseShape.Triangle;

            int value;

            if (buffer.Get(x, y - 1, out value) && value >= DefaultValue && buffer.Get(x + 1, y, out value) && value >= DefaultValue)
            {
                startPoint = SquarePoint.BottomRight;
                square.Init(startPoint, shape);
                var point1       = SquarePoint.BottomLeft;
                var point2       = SquarePoint.TopRight;
                var pointOffset1 = Vector3.right * moveVertextToCorner;
                var pointOffset2 = Vector3.down * moveVertextToCorner;
                var pointPos1    = square.GetAbsolutePosition(point1) + pointOffset1;
                var pointPos2    = square.GetAbsolutePosition(point2) + pointOffset2;
                square.GetNode(point1).Vertex.Pos.x = pointPos1.x;
                square.GetNode(point2).Vertex.Pos.y = pointPos2.y;
            }

            if (buffer.Get(x, y + 1, out value) && value >= DefaultValue && buffer.Get(x - 1, y, out value) && value >= DefaultValue)
            {
                startPoint = SquarePoint.TopLeft;
                square.Init(startPoint, shape);
                var point1       = SquarePoint.BottomLeft;
                var point2       = SquarePoint.TopRight;
                var pointOffset1 = Vector3.up * moveVertextToCorner;
                var pointOffset2 = Vector3.left * moveVertextToCorner;
                var pointPos1    = square.GetAbsolutePosition(point1) + pointOffset1;
                var pointPos2    = square.GetAbsolutePosition(point2) + pointOffset2;
                square.GetNode(point1).Vertex.Pos.y = pointPos1.y;
                square.GetNode(point2).Vertex.Pos.x = pointPos2.x;
            }

            if (buffer.Get(x, y - 1, out value) && value >= DefaultValue && buffer.Get(x - 1, y, out value) && value >= DefaultValue)
            {
                startPoint = SquarePoint.BottomLeft;
                square.Init(startPoint, shape);
                var point1       = SquarePoint.TopLeft;
                var point2       = SquarePoint.BottomRight;
                var pointOffset1 = Vector3.down * moveVertextToCorner;
                var pointOffset2 = Vector3.left * moveVertextToCorner;
                var pointPos1    = square.GetAbsolutePosition(point1) + pointOffset1;
                var pointPos2    = square.GetAbsolutePosition(point2) + pointOffset2;
                square.GetNode(point1).Vertex.Pos.y = pointPos1.y;
                square.GetNode(point2).Vertex.Pos.x = pointPos2.x;
            }

            if (buffer.Get(x, y + 1, out value) && value >= DefaultValue && buffer.Get(x + 1, y, out value) && value >= DefaultValue)
            {
                startPoint = SquarePoint.TopRight;
                square.Init(startPoint, shape);
                var point1       = SquarePoint.TopLeft;
                var point2       = SquarePoint.BottomRight;
                var pointOffset1 = Vector3.right * moveVertextToCorner;
                var pointOffset2 = Vector3.up * moveVertextToCorner;
                var pointPos1    = square.GetAbsolutePosition(point1) + pointOffset1;
                var pointPos2    = square.GetAbsolutePosition(point2) + pointOffset2;
                square.GetNode(point1).Vertex.Pos.x = pointPos1.x;
                square.GetNode(point2).Vertex.Pos.y = pointPos2.y;
            }
        }
コード例 #15
0
 private static SectorEdge BuildEdge(Position square, EdgeSegmentId id, SquarePoint left, SquarePoint right) =>
 SectorEdge.FromPosition(
     square,
     new EdgeSegment(
         id,
         new SectorDescription(1),
         SectorDescription.OutsideLevel,
         Left: left,
         Right: right));