Example #1
0
        private static void DecideKnote(NumeratedConnectedNode nodeZ)
        {
            nodeZ.Parameters.Mc = nodeZ.Node.WL + nodeZ.Node.WR;

            for (var a = 0; a <= _k - 1; a++)
            {
                nodeZ.Parameters.Lc[a] = double.PositiveInfinity;
                nodeZ.Parameters.Rc[a] = double.PositiveInfinity;
            }
            nodeZ.Parameters.Lc[1] = nodeZ.Node.WL;
            nodeZ.Parameters.Rc[1] = nodeZ.Node.WR;

            for (var a = 1; a <= _k - 1; a++)
            {
                for (var b = a; b <= _k - 1; b++)
                {
                    for (var c = 1; c <= _k - 1; c++)
                    {
                        for (var d = c; d <= _k - 1; d++)
                        {
                            for (var e = 0; e <= _k - 1; e++)
                            {
                                nodeZ.Parameters.Qc[a][b][c][d][e] = double.PositiveInfinity;
                            }
                        }
                    }
                }
            }
            if (_k > 2)
            {
                nodeZ.Parameters.Qc[1][2][1][2][2] = 0;
            }
        }
Example #2
0
        private static void DecideJ(NumeratedConnectedNode nodeZ)
        {
            var nodeX = nodeZ.NodeX;
            var nodeY = nodeZ.NodeY;

            nodeZ.Parameters.Mc = nodeX.Parameters.Mc - nodeX.Node.WR +
                                  MinMcyLcyJNode(nodeY.Parameters.Mc, nodeY.Parameters.Lc, _k - 1);
            var s = new double[3];

            var ey      = nodeY.Parameters.E == 0 ? -_k : nodeY.Parameters.E;
            var eyIndex = nodeY.Parameters.E == -_k ? 0 : nodeY.Parameters.E;
            var ex      = nodeX.Parameters.E == 0 ? -_k : nodeX.Parameters.E;
            var exIndex = nodeX.Parameters.E == -_k ? 0 : nodeX.Parameters.E;

            for (var a = 1; a <= _k - 1; a++)
            {
                nodeZ.Parameters.Lc[a] = double.PositiveInfinity;

                if (nodeY.Parameters.B <= a &&
                    Math.Abs(nodeY.Parameters.Qc[nodeY.Parameters.A][nodeY.Parameters.B][nodeY.Parameters.C][nodeY.Parameters.D][eyIndex]) < 0.001)
                {
                    nodeZ.Parameters.Lc[a] = MinLcxJNode(nodeX.Parameters.Lc, a, nodeY.Parameters.B);
                }
                nodeZ.Parameters.Rc[a] = nodeX.Parameters.Rc[a] - nodeZ.Node.WR +
                                         MinMcyLcyJNode(nodeY.Parameters.Mc, nodeY.Parameters.Lc, a);

                for (var b = a; b <= _k - 1; b++)
                {
                    for (var c = 1; c <= _k - 1; c++)
                    {
                        for (var d = c; d <= _k - 1; d++)
                        {
                            for (var e = 0; e <= _k - 1; e++)
                            {
                                s[0] = double.PositiveInfinity;
                                s[1] = double.PositiveInfinity;
                                if (nodeX.Parameters.A == a && nodeX.Parameters.B <= b && nodeX.Parameters.C <= c &&
                                    nodeX.Parameters.D <= d && exIndex == e &&
                                    Math.Abs(nodeX.Parameters.Qc[nodeX.Parameters.A][nodeX.Parameters.B][nodeX.Parameters.C][
                                                 nodeX.Parameters.D][exIndex]) < 0.001)
                                {
                                    s[0] = MinRyJNode(nodeY.Parameters.Rc, b, c, d, nodeX);
                                    s[1] = MinQyJNode(nodeY.Parameters.Qc, nodeX, b, c, d);
                                }

                                s[2] = double.PositiveInfinity;

                                if (nodeY.Parameters.A <= b && nodeY.Parameters.B <= d && nodeY.Parameters.C <= b &&
                                    nodeY.Parameters.D <= d && eyIndex <= b &&
                                    Math.Abs(nodeY.Parameters.Qc[nodeY.Parameters.A][nodeY.Parameters.B][nodeY.Parameters.C][nodeY.Parameters.D][eyIndex]) < 0.001)
                                {
                                    s[2] = MinQxJNode(nodeX.Parameters.Qc, nodeY, a, b, c, d, e);
                                }
                                nodeZ.Parameters.Qc[a][b][c][d][e] = s.Min();
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        private static double MinRyJNode(double[] Ry, int b, int c, int d, NumeratedConnectedNode nodeX)
        {
            var min = double.PositiveInfinity;

            for (var c2 = 1; c2 <= d; c2++)
            {
                var _ex  = nodeX.Parameters.E == 0 ? -_k : nodeX.Parameters.E;
                var maxB = nodeX.Parameters.B > _ex + c2 - 1 ? nodeX.Parameters.B : _ex + c2 - 1;
                if (maxB != b)
                {
                    continue;
                }

                var maxC = nodeX.Parameters.C > c2 ? nodeX.Parameters.C : c2;
                if (maxC != c)
                {
                    continue;
                }

                var maxD = nodeX.Parameters.D > c2 ? nodeX.Parameters.D : c2;
                if (maxD != d)
                {
                    continue;
                }

                if (Ry[c2] < min)
                {
                    min = Ry[c2];
                }
            }
            return(min);
        }
Example #4
0
        private static void DecideP(NumeratedConnectedNode nodeZ)
        {
            var nodeX = nodeZ.NodeX;
            var nodeY = nodeZ.NodeY;

            var ex = nodeX.Parameters.E == 0 ? -_k : nodeX.Parameters.E;
            var ey = nodeY.Parameters.E == 0 ? -_k : nodeY.Parameters.E;

            nodeZ.Parameters.A = nodeX.Parameters.A > nodeY.Parameters.A
                ? nodeX.Parameters.A : nodeY.Parameters.A;
            nodeZ.Parameters.C = nodeY.Parameters.C > nodeX.Parameters.C
                ? nodeY.Parameters.C : nodeX.Parameters.C;
            nodeZ.Parameters.E = ey > ex
                ? ey : ex;

            var s = new int[4];

            s[0] = nodeY.Parameters.B;
            s[1] = nodeX.Parameters.B;
            s[2] = ex + nodeY.Parameters.C;
            s[3] = ey + nodeX.Parameters.C;
            nodeZ.Parameters.B = s.Max();

            s[0] = nodeY.Parameters.D;
            s[1] = nodeX.Parameters.D;
            s[2] = ex + nodeY.Parameters.A;
            s[3] = ey + nodeX.Parameters.A;
            nodeZ.Parameters.D = s.Max();

            nodeZ.Parameters.Mc = nodeY.Parameters.Mc + nodeX.Parameters.Mc
                                  - nodeZ.Node.WL - nodeZ.Node.WR;

            for (var a = 1; a <= _k - 1; a++)
            {
                nodeZ.Parameters.Lc[a] = MinLrpNode(nodeX.Parameters.Lc, nodeY.Parameters.Lc, a)
                                         - nodeX.Node.WL;
                nodeZ.Parameters.Rc[a] = MinLrpNode(nodeX.Parameters.Rc, nodeY.Parameters.Rc, a)
                                         - nodeX.Node.WR;

                for (var b = 1; b < _k - 1; b++)
                {
                    for (var c = 1; c < _k - 1; c++)
                    {
                        for (var d = 1; d < _k - 1; d++)
                        {
                            for (var e = 0; e < _k - 1; e++)
                            {
                                nodeZ.Parameters.Qc[a][b][c][d][e] = MinQcxQcyPNode(nodeX.Parameters.Qc,
                                                                                    nodeY.Parameters.Qc, a, b, c, d, e);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        private static double MinQyJNode(double[][][][][] Qy, NumeratedConnectedNode nodeX, int b, int c, int d)
        {
            var min = double.PositiveInfinity;
            var ex  = nodeX.Parameters.E == 0 ? -_k : nodeX.Parameters.E;

            for (var a2 = 1; a2 <= d; a2++)
            {
                for (var b2 = a2; a2 <= b2 && b2 <= d; b2++)
                {
                    var maxD = nodeX.Parameters.D > b2 ? nodeX.Parameters.D : b2;
                    if (maxD != d)
                    {
                        continue;
                    }

                    var maxC = nodeX.Parameters.C > b2 ? nodeX.Parameters.C : b2;
                    if (maxC != c)
                    {
                        continue;
                    }

                    var maxB = nodeX.Parameters.B > ex + b2 - 1
                        ? nodeX.Parameters.B
                        : ex + b2 - 1;
                    if (maxB != b)
                    {
                        continue;
                    }

                    for (var c2 = 1; c2 <= d; c2++)
                    {
                        for (var d2 = c2; c2 <= d2 && d2 <= d; d2++)
                        {
                            for (var e2 = 0; e2 <= c; e2++)
                            {
                                if (Qy[a2][b2][c2][d2][e2] < min)
                                {
                                    min = Qy[a2][b2][c2][d2][e2];
                                }
                            }
                        }
                    }
                }
            }
            return(min);
        }
Example #6
0
        private static double MinQxJNode(double[][][][][] Qx, NumeratedConnectedNode nodeY, int a, int b, int c, int d, int e)
        {
            var min = double.PositiveInfinity;
            var _e  = e == 0 ? -_k : e;

            for (var b1 = a; b1 <= b; b1++)
            {
                var maxB = b1 > _e + nodeY.Parameters.D - 1 ? b1 : _e + nodeY.Parameters.D - 1;
                if (maxB != b)
                {
                    continue;
                }

                for (var c1 = 1; c1 <= c; c1++)
                {
                    var maxC = c1 > nodeY.Parameters.B ? c1 : nodeY.Parameters.B;
                    if (maxC != c)
                    {
                        continue;
                    }

                    for (var d1 = c1; d1 <= d; d1++)
                    {
                        var maxD = d1 > nodeY.Parameters.B ? d1 : nodeY.Parameters.B;
                        if (maxD != d)
                        {
                            continue;
                        }

                        if (Qx[a][b1][c1][d1][e] < min)
                        {
                            min = Qx[a][b1][c1][d1][e];
                        }
                    }
                }
            }
            return(min);
        }
Example #7
0
        private static void DecideS(NumeratedConnectedNode nodeZ)
        {
            var nodeX   = nodeZ.NodeX;
            var nodeY   = nodeZ.NodeY;
            var ex      = nodeX.Parameters.E == 0 ? -_k : nodeX.Parameters.E;
            var exIndex = nodeX.Parameters.E == -_k ? 0 : nodeX.Parameters.E;
            var ey      = nodeY.Parameters.E == 0 ? -_k : nodeY.Parameters.E;
            var eyIndex = nodeY.Parameters.E == -_k ? 0 : nodeY.Parameters.E;

            nodeZ.Parameters.A = nodeX.Parameters.A > ex + nodeY.Parameters.A - 1
                ? nodeX.Parameters.A
                : ex + nodeY.Parameters.A - 1;
            nodeZ.Parameters.B = nodeX.Parameters.B > ex + nodeY.Parameters.B - 1
                ? nodeX.Parameters.B
                : ex + nodeY.Parameters.B - 1;
            nodeZ.Parameters.C = nodeY.Parameters.C > ey + nodeX.Parameters.C - 1
                ? nodeY.Parameters.C
                : ey + nodeX.Parameters.C - 1;
            nodeZ.Parameters.D = nodeY.Parameters.D > ey + nodeX.Parameters.D - 1
                ? nodeY.Parameters.D
                : ey + nodeX.Parameters.D - 1;
            nodeZ.Parameters.E = ex + ey - 1;
            var s = new double[3];

            s[0] = nodeX.Parameters.Mc + nodeY.Parameters.Mc - nodeX.Node.WR;
            s[1] = double.PositiveInfinity;
            if (Math.Abs(nodeY.Parameters.Rc[nodeY.Parameters.A]) < 0.0001)
            {
                s[1] = MinLCxSNode(nodeX.Parameters.Lc);
            }
            s[2] = double.PositiveInfinity;
            if (Math.Abs(nodeX.Parameters.Lc[nodeX.Parameters.C]) < 0.001)
            {
                s[2] = MinLCxSNode(nodeY.Parameters.Rc);
            }
            nodeZ.Parameters.Mc = s.Min();

            s[2] = double.PositiveInfinity;

            var s2 = new double[2];
            var s4 = new double[4];

            for (var a = 1; a < _k - 1; a++)
            {
                s2[0] = nodeX.Parameters.Mc + nodeY.Parameters.Lc[a] - nodeX.Node.WR;
                s2[1] = double.PositiveInfinity;
                if (Math.Abs(nodeY.Parameters.Qc[nodeY.Parameters.A][nodeY.Parameters.B][nodeY.Parameters.C]
                             [nodeY.Parameters.D][eyIndex]) < 0.001)
                {
                    s2[1] = MinLCxSNode(nodeX.Parameters.Lc, nodeY.Parameters, a);
                }
                nodeZ.Parameters.Lc[a] = s2.Min();

                s2[0] = nodeX.Parameters.Rc[a] + nodeY.Parameters.Mc - nodeX.Node.WR;
                s2[1] = double.PositiveInfinity;
                if (Math.Abs(nodeX.Parameters.Qc[nodeX.Parameters.A][nodeX.Parameters.B][nodeX.Parameters.C]
                             [nodeX.Parameters.D][exIndex]) < 0.001)
                {
                    s2[1] = MinRySNode(nodeX.Parameters, nodeY.Parameters.Rc, a);
                }
                nodeZ.Parameters.Rc[a] = s2.Min();

                for (var b = a; b <= _k - 1; b++)
                {
                    s4[1] = double.PositiveInfinity;

                    if (Math.Abs(nodeY.Parameters.Qc[nodeY.Parameters.A][nodeY.Parameters.B][nodeY.Parameters.C]
                                 [nodeY.Parameters.D][eyIndex]) < 0.001)
                    {
                        s4[1] = MinQcxSNode(nodeX.Parameters.Qc, a, b);
                    }

                    for (var c = 1; c <= _k - 1; c++)
                    {
                        s4[0] = nodeX.Parameters.Rc[a] + nodeY.Parameters.Lc[c] - nodeX.Node.WR;
                        for (var d = c; d <= _k - 1; d++)
                        {
                            s4[2] = double.PositiveInfinity;
                            if (Math.Abs(nodeX.Parameters.Qc[nodeX.Parameters.A][nodeX.Parameters.B][nodeX.Parameters.C]
                                         [nodeX.Parameters.D][exIndex]) < 0.001)
                            {
                                s4[2] = MinQcySNode(nodeY.Parameters.Qc, c, d);
                            }
                            s4[3] = MinS4SNode(nodeX.Parameters.Qc, nodeY.Parameters.Qc, a, b, c, d);
                            nodeZ.Parameters.Qc[a][b][c][d][0] = s4.Min();
                            nodeZ.Parameters.Qc[a][b][c][d][1] = double.PositiveInfinity;
                            for (var e = 2; e <= _k - 1; e++)
                            {
                                nodeZ.Parameters.Qc[a][b][c][d][e] = MinQczSNode(nodeX.Parameters.Qc,
                                                                                 nodeY.Parameters.Qc, a, b, c, d, e);
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public static List <NumeratedConnectedNode> InitializeExample(int k)
        {
            var result = new List <NumeratedConnectedNode>();

            var knotbc = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotbc);

            var knotcd = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotcd);

            var knotef = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotef);

            var knotfg = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotfg);

            var nodeJbc = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = knotbc,
                NodeY = knotcd
            };

            nodeJbc.Node.Type = Node.NodeType.J;
            result.Add(nodeJbc);

            var knotce = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotce);

            var nodeJef = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = knotef,
                NodeY = knotfg
            };

            nodeJef.Node.Type = Node.NodeType.J;
            result.Add(nodeJef);

            var knotfh = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotfh);

            var nodeSbe = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = nodeJbc,
                NodeY = knotce
            };

            nodeSbe.Node.Type = Node.NodeType.S;
            result.Add(nodeSbe);

            var knotbe = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotbe);

            var knoteh = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knoteh);

            var nodeSeh = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = nodeJef,
                NodeY = knotfh
            };

            nodeSeh.Node.Type = Node.NodeType.S;
            result.Add(nodeSeh);

            var knotab = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knotab);

            var nodePbe = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = nodeSbe,
                NodeY = knotbe
            };

            nodePbe.Node.Type = Node.NodeType.P;
            result.Add(nodePbe);

            var nodePeh = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = knoteh,
                NodeY = nodeSeh
            };

            nodePeh.Node.Type = Node.NodeType.P;
            result.Add(nodePeh);

            var knothi = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR   = 1,
                    WL   = 1,
                    Type = Node.NodeType.Knot
                }
            };

            result.Add(knothi);

            var nodeSae = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = knotab,
                NodeY = nodePbe
            };

            nodeSae.Node.Type = Node.NodeType.S;
            result.Add(nodeSae);

            var nodeJeh = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = nodePeh,
                NodeY = knothi
            };

            nodeJeh.Node.Type = Node.NodeType.J;
            result.Add(nodeJeh);

            var nodeSah = new NumeratedConnectedNode(k)
            {
                Node =
                {
                    WR = 1,
                    WL = 1
                },
                NodeX = nodeSae,
                NodeY = nodeJeh
            };

            nodeSah.Node.Type = Node.NodeType.S;
            result.Add(nodeJeh);

            return(result);
        }