示例#1
0
        private void configure(TypeOfEdge tofE, int nofN)
        {
            t = tofE;
            n = new INode[nofN];

            switch (tofE)
            {
            case TypeOfEdge.Directed:

                c = new object[nofN][];

                for (int i = 0; i < nofN; i++)
                {
                    c[i] = new object[nofN];
                }

                break;

            case TypeOfEdge.Undirected:

                c = new object[nofN][];

                for (int i = 0; i < nofN; i++)
                {
                    c[i] = new object[nofN - i];
                }

                break;
            }
        }
示例#2
0
        public Graph Configure <T, U>(TypeOfEdge tofE, T[] node, params U[] cost)
            where T : INode
        {
            configure(tofE, node.Length);

            for (int i = 0; i < node.Length; i++)
            {
                node[i].ID = i;
                n[i]       = node[i];
            }

            int s = 0;

            if (cost != null)
            {
                switch (tofE)
                {
                case TypeOfEdge.Directed:
                    s = node.Length * node.Length;
                    if (cost.Length != s)
                    {
                        throw new Exception();
                    }
                    for (int n = 0, i = 0; i < node.Length; i++)
                    {
                        for (int j = 0; j < node.Length; j++)
                        {
                            c[i][j] = cost[n++];
                        }
                    }

                    break;

                case TypeOfEdge.Undirected:
                    s = (node.Length * (node.Length + 1)) / 2;
                    if (cost.Length != s)
                    {
                        throw new Exception();
                    }
                    for (int n = 0, i = 0; i < node.Length; i++)
                    {
                        for (int j = 0; j < node.Length - i; j++)
                        {
                            c[i][j] = cost[n++];
                        }
                    }

                    break;
                }
            }

            return(this);
        }
示例#3
0
        public U GetCost <U>(int sID, int tID)
        {
            U c = default(U);

            switch (t)
            {
            case TypeOfEdge.Directed:
                c = (U)this.c[sID][tID];
                break;

            case TypeOfEdge.Undirected:
                int s = sID, t = tID;
                if (s > t)
                {
                    s = tID;
                    t = sID;
                }
                c = (U)this.c[s][t - s];
                break;
            }

            return(c);
        }