示例#1
0
 public void SetUsed(Vertex[] vList, Edge[,] eList, int[] degList, int a, int b, int zoomlevel)
 {
     for (int index = 0; index < degList[a]; index++)
     {
         if (eList[a, index].NodeId == b)
         {
             if (eList[a, index].Used > 0)
             {
                 return;
             }
             else
             {
                 eList[a, index].Used = zoomlevel;
             }
         }
     }
     for (int index = 0; index < degList[b]; index++)
     {
         if (eList[b, index].NodeId == a)
         {
             if (eList[b, index].Used > 0)
             {
                 return;
             }
             else
             {
                 eList[b, index].Used = zoomlevel;
             }
         }
     }
 }
示例#2
0
 public DenseGraph(int n, bool directed)
 {
     this.n        = n;
     edges         = new Edge[n, n];
     this.m        = 0;
     this.directed = directed;
 }
		public void createGraph(string fileName) {
			//read in XML file and build an adjacency list
			if (!File.Exists(fileName)) return;
			StreamReader sRead = new StreamReader(fileName);
			string fileString = sRead.ReadToEnd();
			sRead.Close();
			XmlDocument doc = new XmlDocument();
			doc.LoadXml(fileString);
			if (doc.ChildNodes[0].Name == "adjacency_list") {
				foreach (XmlNode node in doc.ChildNodes[0]) {
					V.Add(new Vertex(node.Attributes[0].Value, V.Count)); //add vertex to vertex list
					VDict.Add(node.Attributes[0].Value, V[V.Count - 1]);
				}
				_matrix = new Edge[V.Count, V.Count];
				for (int i = 0; i < V.Count; ++i) {
					XmlNode node = doc.ChildNodes[0].ChildNodes[i]; //for each vertex in the graph
					string s = node.Attributes[1].Value; //s is the adjacency list of the vertex
					string t = node.Attributes[2].Value; //t is the weight list 
					//pull out edge weights here too
					//foreach (Vertex v in V) {
					while(s != "") { //if the vertex has adjacent vertices 
						Vertex v = VDict[s.Substring(0, s.IndexOf(","))];
						//if (v.Name == s.Substring(0, s.IndexOf(","))) { // if vertex names match
						double w = double.Parse(t.Substring(0, t.IndexOf(",")));
						E.Add(new Edge(V[i], v, w)); //add an edge between vertices
						_matrix[V[i].Index, v.Index] = E[E.Count - 1];
						s = s.Remove(0, s.IndexOf(",") + 1); //parse out comma
						t = t.Remove(0, t.IndexOf(",") + 1); //parse out comma
					}
				}
			}
		}
示例#4
0
        static int FindMinDist(Edge[,] Graph, int[] dist, int[] cost, bool[] collected)
        { /* 返回未被收录顶点中dist最小者 */
            int MinV = int.MaxValue;
            int V;
            int MinDist = int.MaxValue;
            int MinCost = int.MaxValue;

            for (V = 0; V < Graph.GetLength(0); V++)
            {
                if (collected[V] == false && dist[V] < MinDist)
                {
                    /* 若V未被收录,且dist[V]更小 */
                    MinDist = dist[V]; /* 更新最小距离 */
                    MinCost = cost[V];
                    MinV    = V;       /* 更新对应顶点 */
                }
                else if (collected[V] && dist[V] == MinDist && cost[V] < MinCost)
                {
                    /* 若V已被收录,且V的路径于当前最小路径相同,但费用较小 */
                    MinDist = dist[V]; /* 更新最小距离 */
                    MinCost = cost[V];
                    MinV    = V;       /* 更新对应顶点 */
                }
            }
            if (MinDist < int.MaxValue) /* 若找到最小dist */
            {
                return(MinV);           /* 返回对应的顶点下标 */
            }
            else
            {
                return(-1);  /* 若这样的顶点不存在,返回错误标记 */
            }
        }
        public GraphVertexMatrix(Vertex[] nodeSet, Edge [,] edgeSet)
        {
            if (nodeSet == null)
            {
                this.nodeSet = new Vertex[size];
                for (int i = 0; i < size; ++i)
                {
                    this.nodeSet[i] = null;
                }
            }
            else
            {
                this.nodeSet = nodeSet;
            }


            if (edgeSet == null)
            {
                this.edgeSet = new Edge[size, size];
                for (int i = 0; i < size; ++i)
                {
                    for (int j = 0; j < size; ++j)
                    {
                        this.edgeSet[i, j] = null;
                    }
                }
            }
            else
            {
                this.edgeSet = edgeSet;
            }
        }
示例#6
0
 private static void BuildGraph(int n, int m)
 {
     Graph = new Edge[n, n];
     for (int i = 0; i <= n - 1; i++)
     {
         for (int j = 0; j <= n - 1; j++)
         {
             if (i != j)
             {
                 Graph[i, j].Distance = int.MaxValue;
                 Graph[i, j].Cost     = int.MaxValue;
             }
         }
     }
     for (int i = 0; i <= m - 1; i++)
     {
         string   str      = Console.ReadLine();
         string[] strs     = str.Split(new string[] { " " }, StringSplitOptions.None);
         int      a        = Convert.ToInt32(strs[0]);
         int      b        = Convert.ToInt32(strs[1]);
         int      distance = Convert.ToInt32(strs[2]);
         int      cost     = Convert.ToInt32(strs[3]);
         Graph[a, b].Distance = distance;
         Graph[b, a].Distance = distance;
         Graph[a, b].Cost     = cost;
         Graph[b, a].Cost     = cost;
     }
 }
示例#7
0
 static void Main(string[] args)
 {
     TSP_Mrowkowy.Program.cords = input(ref ile_miast);
     edges = new Edge[ile_miast, ile_miast];
     TSP_Mrowkowy.Edge.ro    = 0.5;
     TSP_Mrowkowy.Ant.rnd    = new Random();
     TSP_Mrowkowy.Ant.edges  = edges;
     TSP_Mrowkowy.Ant.cords  = cords;
     TSP_Mrowkowy.Ant.cities = ile_miast;
     for (int i = 0; i < ile_miast; i++)
     {
         for (int j = 0; j < ile_miast; j++)
         {
             if (i != j)
             {
                 edges[i, j] = new Edge(cords[i], cords[j]);
             }
         }
     }
     okno = new Form1();
     if (filename == "berlin52" || filename == "kroC100" || filename == "pr76")
     {
         load_opt();
     }
     run_greedy();
     //else
     //    edges[i, j] = new Edge(Cord.Zero(), Cord.Zero());
     //wypiszPunkty();
     //wypiszDist();
     Menu.Start();
 }
示例#8
0
    List <int> GetSuccessorNodes(Edge[,] inEdges, List <Node> inNodes, int inNumOfNodes, int inCurrentNodeIndex)
    {
        List <int> successorNodes = new List <int>();

        for (int column = 0; column < inNumOfNodes; column++)
        {
            if (inCurrentNodeIndex == column)
            {
                continue;
            }

            Edge tempEdge1;
            Edge tempEdge2;
            tempEdge1 = inEdges[column, inCurrentNodeIndex];
            tempEdge2 = inEdges[inCurrentNodeIndex, column];

            if (tempEdge1 != null || tempEdge2 != null)
            {
                if (false == closedList.Contains(column))
                {
                    int nodeIndex = column;
                    successorNodes.Add(nodeIndex);
                }
            }
        }

        return(successorNodes);
    }
示例#9
0
 public AdjacencyGraph(Edge[,] adjacency)
 {
     for (int i = 0; i < adjacency.Length; i++)
     {
         Vertexes[i] = adjacency[i, 0].num;
     }
     Adjacency = adjacency;
 }
    public Vector3[] GenerateNodeCubicLocations(CubicGraphProperties cubicGraphProperties, out int[][] edges)
    {
        int nodesCount = cubicGraphProperties.PartsCount * cubicGraphProperties.PartsCount * cubicGraphProperties.PartsCount;

        connections = new Edge[nodesCount, nodesCount];
        Vector3[] nodesLocations = _cubicGraphGenerator.GenerateGraph(cubicGraphProperties, out edges);
        return(nodesLocations);
    }
示例#11
0
        private Twist(string name, Edge[,] edgeCycles, Corner[] cornerCycle, Center[,] centerCycles)
        {
            this._name      = name;
            edgePermutation = Enumerable.Range(0, 24).ToArray();
            int length = edgeCycles.GetLength(1);

            for (int i = 0; i < edgeCycles.GetLength(0); i++)
            {
                for (int j = 0; j < length; j++)
                {
                    int index1 = edgeCycles [i, j].index;
                    int index2 = edgeCycles [i, (j + 1) % length].index;
                    edgePermutation [index1] = index2;
                }
            }
            pairPermutation = Enumerable.Range(0, 12).ToArray();
            length          = edgePermutation.Length;
            int[] pairs = Edge.getPairs();
            for (int j = 0; j < length; j++)
            {
                pairPermutation [pairs [j]] = pairs [edgePermutation [j]];
            }
            cornerPermutation = Enumerable.Range(0, 8).ToArray();
            cornerOrientation = new int[8];
            length            = cornerCycle.Length;
            Faces baseFace = getBaseFace(cornerCycle);

            for (int j = 0; j < length; j++)
            {
                int index1 = cornerCycle [j].index;
                int index2 = cornerCycle [(j + 1) % length].index;
                cornerPermutation [index1] = index2;
                int faceIdx1 = getCornerFaceIndex(baseFace, cornerCycle [j]);
                int faceIdx2 = getCornerFaceIndex(baseFace, cornerCycle [(j + 1) % length]);
                cornerOrientation [index1] = (faceIdx1 - faceIdx2) % 3;
            }
            centerPermutation = Enumerable.Range(0, 24).ToArray();
            length            = centerCycles.GetLength(1);
            for (int i = 0; i < centerCycles.GetLength(0); i++)
            {
                for (int j = 0; j < length; j++)
                {
                    int index1 = centerCycles [i, j].index;
                    int index2 = centerCycles [i, (j + 1) % length].index;
                    centerPermutation [index1] = index2;
                }
            }

            pairOrientation = new int[12];
            edgeOrientation = new int[24];
            int[] signs = Edge.getSigns();
            for (int i = 0; i < 24; i++)
            {
                pairOrientation [pairs [edgePermutation [i]]] = signs [i] * signs [edgePermutation [i]] == 1 ? 0 : 1;
                edgeOrientation [edgePermutation [i]]         = signs [i] * signs [edgePermutation [i]] == 1 ? 0 : 1;
            }
        }
示例#12
0
        protected SchedulerGraph(IList <T> tasks)
        {
            _tasks   = tasks;
            AllTasks = new ReadOnlyCollection <T>(_tasks);

            _edges             = new Edge[TaskCount, TaskCount];
            _followingTasks    = new bool[TaskCount, TaskCount];
            _incomingEdgeCount = new int[TaskCount];
        }
示例#13
0
        public void addEdge(int iVertexIndex0, int iVertexIndex1, System.Drawing.Color cEdgeColor, System.Drawing.Color cLabelColor)
        {
            //Make sure we only deal with the upper triangle of the adjacency matrix
            if (iVertexIndex0 > iVertexIndex1)
            {
                Swap(ref iVertexIndex0, ref iVertexIndex1);
            }

            //Make sure the adjancy matrix is large enough
            if (iVertexIndex1 >= eAdjMatrix.GetUpperBound(0))
            {
                //Enlarge Adjacency matrix
                int iRow, iCol, iOldSize = eAdjMatrix.GetUpperBound(0);
                int iNewSize = iVertexIndex1 + iAdjMatrixNumVerticesStep;
                Edge[,] eTempAdj = new Edge[iNewSize, iNewSize];
                Edge eCurEdge;

                //Copy old data
                for (iRow = 0; iRow < iOldSize; iRow++)
                {
                    for (iCol = 0; iCol < iOldSize; iCol++)
                    {
                        eCurEdge = new Edge(eAdjMatrix[iRow, iCol].GetVertex0(), eAdjMatrix[iRow, iCol].GetVertex1(), cEdgeColor, cLabelColor);
                        eCurEdge.SetWeight(eAdjMatrix[iRow, iCol].GetWeight());

                        eTempAdj[iRow, iCol] = eCurEdge;
                    }
                }

                eAdjMatrix = new Edge[iNewSize, iNewSize];
                for (iRow = 0; iRow < iOldSize; iRow++)
                {
                    for (iCol = 0; iCol < iOldSize; iCol++)
                    {
                        eCurEdge = new Edge(eTempAdj[iRow, iCol].GetVertex0(), eTempAdj[iRow, iCol].GetVertex1(), cEdgeColor, cLabelColor);
                        eCurEdge.SetWeight(eTempAdj[iRow, iCol].GetWeight());

                        eAdjMatrix[iRow, iCol] = eCurEdge;
                    }
                }

                //Add new data
                for (iRow = iOldSize; iRow < iNewSize; iRow++)
                {
                    for (iCol = iOldSize; iCol < iNewSize; iCol++)
                    {
                        eAdjMatrix[iRow, iCol] = new Edge(-1, -1, cEdgeColor, cLabelColor);
                    }
                }
            }

            eAdjMatrix[iVertexIndex0, iVertexIndex1].SetVerticesV0V1(iVertexIndex0, iVertexIndex1);
            eAdjMatrix[iVertexIndex0, iVertexIndex1].setLabelColor(cLabelColor);
            eAdjMatrix[iVertexIndex0, iVertexIndex1].setColor(cEdgeColor);
        }
示例#14
0
 public Dijkstra(decimal [,] mtr, int size)
 {
     _size  = size;
     Vertex = new Vertex[_size];//создали массив вершин размера матрицы
     Edges  = new Edge[_size, _size];
     for (int i = 0; i < _size; i++)
     {
         Vertex[i] = new Vertex(i);
     }
     CreateEdges(mtr);//создание ребер в графе
 }
示例#15
0
        public Graph(List <Node> nodeList, List <Edge> edgeList)
        {
            this.nodeList = nodeList;
            this.edgeList = edgeList;

            array = new Edge[nodeList.Count, nodeList.Count];

            foreach (Edge e in edgeList)
            {
                array[e.startNode.id, e.endNode.id] = e;
            }
        }
    public void DestroyGraph()
    {
        List <GameObject> children = new List <GameObject>();

        foreach (Transform child in transform)
        {
            children.Add(child.gameObject);
        }
        children.ForEach(Destroy);
        connections = null;
        Nodes       = null;
    }
示例#17
0
 public Graph(int size)
 {
     vertexCount = size;
     demands     = new int[size];
     edges       = new Edge[size, size];
     for (int i = 0; i < size - 1; i++)
     {
         for (int j = i + 1; j < size; j++)
         {
             edges[i, j] = new Edge(i, j, 0, 0);
         }
     }
 }
 public void Add(Vertex vertex)
 {
     vertexIndex.Add(vertex);
     ++count;
     Edge[,] temp = new Edge[count, count];
     for (int i = 0; i < count - 1; i++)
     {
         for (int j = 0; j < count - 1; j++)
         {
             temp[i, j] = matrix[i, j];
         }
     }
     matrix = temp;
 }
    public Vector3[] GenerateNodeConicLocations(ConicGraphProperties conicGraphProperties, out int[][] edges)
    {
        if (conicGraphProperties.FloorsNodesCounts == null)
        {
            int[] floorNodesCounts = GraphGeneratorHelper.GenerateFloorNodesCounts(conicGraphProperties.FloorsCount, -1,
                                                                                   conicGraphProperties.FloorsCount);
            conicGraphProperties.FloorsNodesCounts = floorNodesCounts;
        }
        int nodesCount = conicGraphProperties.FloorsNodesCounts.Sum(a => a);

        connections = new Edge[nodesCount, nodesCount];
        Vector3[] nodesLocations = _conicGraphGenerator.GenerateGraph(conicGraphProperties, out edges);
        return(nodesLocations);
    }
    public Vector3[] GenerateNodeSpiralLocations(SpiralGraphProperties spiralGraphProperties, out int[][] edges)
    {
        if (spiralGraphProperties.FloorsNodesCounts == null)
        {
            int[] floorNodesCounts = GraphGeneratorHelper.GenerateFloorNodesCounts(spiralGraphProperties.FloorsCount, -1,
                                                                                   spiralGraphProperties.FloorsCount);
            spiralGraphProperties.FloorsNodesCounts = floorNodesCounts;
        }
        int nodesCount = spiralGraphProperties.FloorsNodesCounts.Sum(a => a);

        connections = new Edge[nodesCount, nodesCount];
        Vector3[] nodesLocations = _spiralGraphGenerator.GenerateGraph(spiralGraphProperties, out edges);
        return(nodesLocations);
    }
示例#21
0
        public void Initialize()
        {
            int iCol, iRow;

            iVertexRadius = 30;
            eAdjMatrix    = new Edge[iAdjMatrixNumVerticesStep, iAdjMatrixNumVerticesStep];
            lVertexList.Clear();

            for (iRow = 0; iRow < iAdjMatrixNumVerticesStep; iRow++)
            {
                for (iCol = 0; iCol < iAdjMatrixNumVerticesStep; iCol++)
                {
                    eAdjMatrix[iRow, iCol] = new Edge(-1, -1);
                }
            }
        }
示例#22
0
        public Ant(ref Edge[,] costMatrix)
        {
            Debug.Assert(costMatrix.GetLength(0) > 0);
            this.costMatrix = costMatrix;
            visited = new bool[costMatrix.GetLength(0)];
            route = new List<int>(costMatrix.GetLength(0));
            //Generate the route.
            route.Add(BeginTraversal());
            while (route.Count < costMatrix.GetLength(0) && route.Last() != -1)
                route.Add(TraverseFrom(route.Last()));
            complete = route.Last() != -1;

            if (complete)
            {
                setTotalCost();
            }
        }
示例#23
0
 public PathData[,] pathMap; //所有点的最短路径矩阵(每个点的数据都是一条路径列表)
 //初始化num个点的图
 public TrailerGraph(int num = MAX_NUMBER)
 {
     //初始化邻接矩阵和顶点数组
     adjMatrix = new Edge[num, num];
     vertexes  = new Vertex[num];
     //将代表邻接矩阵的表全初始化为0
     for (int i = 0; i < num; i++)
     {
         for (int j = 0; j < num; j++)
         {
             adjMatrix[i, j].vertexNum1 = i;
             adjMatrix[i, j].vertexNum2 = j;
             adjMatrix[i, j].lineType   = LineType.Straight;
             adjMatrix[i, j].weight     = GlobalVaribles.INFINITY;//初始化weight为最大值
         }
     }
 }
示例#24
0
 /// <summary>
 /// Graph with distances and pheromones
 /// </summary>
 /// <param name="size"></param>
 /// <param name="distances"></param>
 /// <param name="pheromones">If null every edge starts with pheromone equal to 0</param>
 public Graph(int size, double[,] distances, int[] demands, double[,] pheromones = null)
 {
     vertexCount  = size;
     this.demands = demands;
     if (pheromones == null)
     {
         pheromones = new double[size, size];
     }
     edges = new Edge[size, size];
     for (int i = 0; i < size - 1; i++)
     {
         for (int j = i + 1; j < size; j++)
         {
             edges[i, j] = new Edge(i, j, distances[i, j], pheromones[i, j]);
         }
     }
 }
示例#25
0
        public AdjacencyGraph(List <int> vertex)
        {
            Vertexes  = new List <int>(vertex);
            Adjacency = new Edge[vertex.Count, vertex.Count];
            Random random = new Random();

            for (int i = 0; i < vertex.Count; i++)
            {
                Adjacency[i, i].num    = 0;
                Adjacency[i, i].weight = int.MaxValue;
                for (int j = i + 1; j < vertex.Count; j++)
                {
                    Adjacency[i, j].num    = random.Next(2);
                    Adjacency[i, j].weight = random.Next(1, 15);
                    Adjacency[j, i]        = Adjacency[i, j];
                }
            }
        }
示例#26
0
        private static Edge[,] CloneEdges(Edge[,] source)
        {
            int count = source.GetLength(0);

            Edge[,] copy = new Edge[count, count];

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < count; j++)
                {
                    copy[i, j] = new Edge
                    {
                        Weight = source[i, j].Weight
                    };
                }
            }

            return(copy);
        }
示例#27
0
        public Ant(ref Edge[,] costMatrix)
        {
            Debug.Assert(costMatrix.GetLength(0) > 0);
            this.costMatrix = costMatrix;
            visited         = new bool[costMatrix.GetLength(0)];
            route           = new List <int>(costMatrix.GetLength(0));
            //Generate the route.
            route.Add(BeginTraversal());
            while (route.Count < costMatrix.GetLength(0) && route.Last() != -1)
            {
                route.Add(TraverseFrom(route.Last()));
            }
            complete = route.Last() != -1;

            if (complete)
            {
                setTotalCost();
            }
        }
        public void Del(Vertex vertex)
        {
            --count;
            Edge[,] temp = new Edge[count, count];
            int diff = vertexIndex.IndexOf(vertex);

            for (int i = 0; i < count + 1; i++)
            {
                for (int j = 0; j < count + 1; j++)
                {
                    if (i != diff && j != diff)
                    {
                        temp[i - ((i > diff) ? 1 : 0),
                             j - ((j > diff) ? 1 : 0)] = matrix[i, j];
                    }
                }
            }
            matrix = temp;
            vertexIndex.Remove(vertex);
        }
示例#29
0
 public AdjacencyGraph(float[,] weigths, int numVertex)
 {
     Vertexes  = new List <int>();
     Adjacency = new Edge[numVertex, numVertex];
     for (int i = 0; i < numVertex; i++)
     {
         for (int j = 0; j < numVertex; j++)
         {
             Adjacency[i, j].weight = weigths[i, j];
             if (weigths[i, j] > 0)
             {
                 Adjacency[i, j].num = 1;
             }
         }
     }
     for (int i = 0; i < numVertex; i++)
     {
         Vertexes.Add(i);
     }
 }
示例#30
0
 public Matrix(int[,] matrix, int N)
 {
     _N     = N;
     _edges = new Edge[_N, _N];
     Fill();
     for (var i = 0; i < _N; i++)
     {
         for (var j = 0; j < _N; j++)
         {
             if (matrix[i, j] != 0)
             {
                 _edges[i, j].Flow = matrix[i, j];
                 if (j != _N - 1)
                 {
                     _edges[j, i].Flow         = matrix[i, j];
                     _edges[j, i].CurrentUsage = matrix[i, j];
                 }
             }
         }
     }
 }
示例#31
0
    // Build graph from given textfile, vertex/edge Prefabs
    public void buildGraph(TextAsset adjMatrix, TextAsset pos, Vertex vertexPrefab, Edge edgePrefab)
    {
        // Initialize the vertex_list for new graph
        vertex_list = new List <Vertex>();

        this.vertexPrefab = vertexPrefab;
        this.edgePrefab   = edgePrefab;

        // Parse the textfiles
        adjMatrixLines = Regex.Split(adjMatrix.text, "\n");
        posLines       = Regex.Split(pos.text, "\n");

        // Initialize e
        edges_list = new Edge[adjMatrixLines.Length - 1, adjMatrixLines.Length - 1];

        // Store the smallest y-value for the plane
        int minYValue = Int32.MaxValue;
        int maxYValue = Int32.MinValue;

        // instantiate vertices and edges based on csv file.
        for (int i = 0; i < adjMatrixLines.Length - 1; i++)
        {
            string valueLineAdj = adjMatrixLines[i];
            string valueLinePos = posLines[i];

            string[] valuesAdj = Regex.Split(valueLineAdj, ",");
            string[] valuesPos = Regex.Split(valueLinePos, ",");


            // Get the x-y-z coordinate of each vertex
            int     x_coord  = Int32.Parse(valuesPos[0]);
            int     y_coord  = Int32.Parse(valuesPos[1]);
            int     z_coord  = Int32.Parse(valuesPos[2]);
            Vector3 position = new Vector3(x_coord, y_coord, z_coord);

            // Update the smallest and largest y-values
            if (y_coord < minYValue)
            {
                minYValue = y_coord;
            }
            if (y_coord > maxYValue)
            {
                maxYValue = y_coord;
            }

            // instantiate vertices
            Vertex obj = Instantiate(vertexPrefab, position, Quaternion.identity);
            obj.adjacentEdges = new HashSet <Edge>();

            vertex_list.Add(obj);

            if (i != 0)
            {
                for (int j = 0; j < i; j++)
                {
                    int test = Int32.Parse(valuesAdj[j]);
                    if (test == 1)
                    {
                        Vector3 other_pos = vertex_list[j].transform.position;
                        Vector3 edge_pos  = Vector3.Lerp(position, other_pos, 0.5f);

                        // Instantiate edge
                        Edge e      = Instantiate(edgePrefab, edge_pos, Quaternion.identity);
                        var  offset = other_pos - position;
                        var  scale  = new Vector3(0.5f, offset.magnitude / 2, 0.5f);
                        e.transform.up         = offset;
                        e.transform.localScale = scale;
                        e.adjacentVertices     = new HashSet <Vertex>();
                        edges_list[i, j]       = e;
                    }
                }
            }
        }

        for (int i = 0; i < adjMatrixLines.Length - 1; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (edges_list[i, j] != null)
                {
                    vertex_list[i].adjacentEdges.Add(edges_list[i, j]);
                    vertex_list[j].adjacentEdges.Add(edges_list[i, j]);
                    edges_list[i, j].adjacentVertices.Add(vertex_list[i]);
                    edges_list[i, j].adjacentVertices.Add(vertex_list[j]);
                }
            }
        }

        Answer = Int32.Parse(adjMatrixLines[adjMatrixLines.Length - 1]);

        // Adjust the height of the plane and the camerarig according to the min max coordinates of the vertices
        GameObject[] graphComponents = UnityEngine.Object.FindObjectsOfType <GameObject>();
        for (int i = 0; i < graphComponents.Length; i++)
        {
            if (graphComponents[i].name == "Plane")
            {
                Vector3 planeCoord = graphComponents[i].transform.position;
                planeCoord.y = minYValue - 5;
                graphComponents[i].transform.position = planeCoord;
            }
            if (graphComponents[i].name == "[CameraRig]")
            {
                Vector3 planeCoord = graphComponents[i].transform.position;
                planeCoord.y = (minYValue + maxYValue) / 2;
                graphComponents[i].transform.position = planeCoord;
            }
        }
    }
 public AdjacencyMatrix()
 {
     count       = 0;
     vertexIndex = new List <Vertex>();
     matrix      = new Edge[count, count];
 }
示例#33
0
		//public AxisSweep3Internal(ref Vector3 worldAabbMin,ref Vector3 worldAabbMax, int handleMask, int handleSentinel, int maxHandles = 16384, OverlappingPairCache* pairCache=0,bool disableRaycastAccelerator = false);
		public AxisSweep3Internal(ref Vector3 worldAabbMin, ref Vector3 worldAabbMax, int handleMask, ushort handleSentinel, ushort userMaxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator)
		{
			m_bpHandleMask = (handleMask);
			m_handleSentinel = (handleSentinel);
			m_pairCache = (pairCache);
			m_userPairCallback = null;
			m_ownsPairCache = (false);
			m_invalidPair = 0;
			m_raycastAccelerator = null;
			ushort maxHandles = (ushort)(userMaxHandles+1);//need to add one sentinel handle

			if (m_pairCache == null)
			{
				m_pairCache = new HashedOverlappingPairCache();
				m_ownsPairCache = true;
			}

			if (!disableRaycastAccelerator)
			{
				m_nullPairCache = new NullPairCache();
				m_raycastAccelerator = new DbvtBroadphase(m_nullPairCache);//m_pairCache);
				m_raycastAccelerator.m_deferedcollide = true;//don't add/remove pairs
			}

			//btAssert(bounds.HasVolume());

			// init bounds
			m_worldAabbMin = worldAabbMin;
			m_worldAabbMax = worldAabbMax;

			Vector3 aabbSize = m_worldAabbMax - m_worldAabbMin;

			int maxInt = m_handleSentinel;

			m_quantize = new Vector3((float)maxInt,(float)maxInt,(float)maxInt) / aabbSize;

			// allocate handles buffer, using btAlignedAlloc, and put all handles on free list
			m_pHandles = new Handle[maxHandles];
			for (int i = 0; i < m_pHandles.Length; ++i)
			{
				m_pHandles[i] = new Handle();
			}

			m_maxHandles = maxHandles;
			m_numHandles = 0;

			// handle 0 is reserved as the null index, and is also used as the sentinel
			m_firstFreeHandle = 1;
			{
				for (ushort i = m_firstFreeHandle; i < maxHandles; i++)
				{
					ushort nextFree = (ushort)(i + (ushort)1);
					m_pHandles[i].SetNextFree(nextFree);
				}
				m_pHandles[maxHandles - 1].SetNextFree(0);
			}

			{
				m_pEdges = new Edge[3, (maxHandles * 2)];
				// allocate edge buffers
				for (int i = 0; i < 3; i++)
				{
					for (int j = 0; j < maxHandles * 2; ++j)
					{
						m_pEdges[i,j] = new Edge();
					}
				}
			}
			//removed overlap management

			// make boundary sentinels
    	
			m_pHandles[0].SetClientObject(null);

			for (int axis = 0; axis < 3; axis++)
			{
				m_pHandles[0].m_minEdges[axis] = 0;
				m_pHandles[0].m_maxEdges[axis] = 1;

				m_pEdges[axis,0].m_pos = 0;
				m_pEdges[axis,0].m_handle = 0;
				m_pEdges[axis,1].m_pos = m_handleSentinel;
				m_pEdges[axis,1].m_handle = 0;

		    
#if DEBUG_BROADPHASE
		    debugPrintAxis(axis);
#endif //DEBUG_BROADPHASE

			}
		}