コード例 #1
0
    public VertexGraph getRandomNeighbour(VertexGraph current) //wander
    {
        int s = current.adyacencia.Count;
        int i = Random.Range(0, s);

        return(vertices[current.adyacencia[i]]);
    }
コード例 #2
0
        public void CanAddNodeTest()
        {
            VertexGraph graph = new VertexGraph();

            graph.AddVertex(new Vertex());
            Assert.Equal(1, graph.Size());
        }
コード例 #3
0
        public void Empty()
        {
            var graph = new VertexGraph();

            Assert.AreEqual(0, graph.Count);
            graph.Clear();
        }
コード例 #4
0
        /// <summary>
        /// Internal: Create a vertex graph from a set of hexagons. It is the
        /// responsibility of the caller to call destroyVertexGraph on the populated
        /// graph, otherwise the memory in the graph nodes will not be freed.
        /// </summary>
        /// <param name="h3Set">Set of hexagons</param>
        /// <returns>Output graph</returns>
        /// <!--
        /// algos.c
        /// h3SetToVertexGraph
        /// -->
        public static VertexGraph ToVertexGraph(this List<H3Index> h3Set)
        {
            if (h3Set.Count<1)
            {
                // We still need to init the graph, or calls to destroyVertexGraph will
                // fail
                return new VertexGraph();
            }

            var graph = new VertexGraph();

            for (int i = 0; i < h3Set.Count; i++)
            {
                var vertices = h3Set[i].ToGeoBoundary();
                for (int j = 0; j < vertices.NumVerts; j++)
                {
                    var fromVtx = vertices.Verts[j];
                    var toVtx = vertices.Verts[(j + 1) % vertices.NumVerts];
                    var edge = graph.FindEdge(toVtx, fromVtx);
                    if (edge != null)
                    {
                        graph.RemoveNode(edge);
                    }
                    else
                    {
                        graph.AddNode(fromVtx, toVtx);
                    }
                }
            }

            return graph;
        }
コード例 #5
0
        /// <summary>
        /// Internal: Create a LinkedGeoPolygon from a vertex graph. It is the
        /// responsibility of the caller to call destroyLinkedPolygon on the populated
        /// linked geo structure, or the memory for that structure will not be freed.
        /// </summary>
        /// <param name="graph">Input graph</param>
        /// <returns>Output polygon</returns>
        /// <!--
        /// algos.c
        /// void _vertexGraphToLinkedGeo
        /// -->
        public static LinkedGeoPolygon ToLinkedGeoPolygon(this VertexGraph graph)
        {
            var result = new LinkedGeoPolygon();

            while (graph.Count > 0)
            {
                var edge = graph.FirstNode();
                var loop = new LinkedGeoLoop();
                while (edge.HasValue)
                {
                    loop.AddLinkedCoord(edge.Value.From);
                    //loop.GeoCoordList.AddLast(edge.Value.From);
                    var nextVertex = edge.Value.To;
                    graph.RemoveNode(edge.Value);
                    edge = graph.FindVertex(nextVertex);
                }

                if (loop.Count > 0)
                {
                    result.AddLinkedLoop(loop);
                }
            }

            return(result);
        }
コード例 #6
0
        public void makeVertexGraph()
        {
            VertexGraph graph = new VertexGraph(10, 9);

            Assert.True(graph.numBuckets == 10, "numBuckets set");
            Assert.True(graph.size == 0, "size set");
        }
コード例 #7
0
        //************************************************************************************************
        // Обработка особенности условной вершины - 3 места для вывода линии, но из вершины может выходить только 2 линии.
        //************************************************************************************************

        //Проверка блокировки третьего места условной вершины.
        private void checkLockPlaceFromCondition(VertexGraph condition)
        {
            //Подсчет количества занятых линиями мест.
            int numberBusyPlace = 0;

            for (int i = 0; i < 3; i++)
            {
                if (condition.getPlaceOutputLine(i).getLine() != null)
                {
                    numberBusyPlace++;
                }
            }
            //Если 2 из 3 места заняты, то третье место блокируется.
            if (numberBusyPlace == 2)
            {
                //Поиск не занятого места, чтобы его заблокировать.
                for (int i = 0; i < 3; i++)
                {
                    if (condition.getPlaceOutputLine(i).getLine() == null)
                    {
                        condition.getPlaceOutputLine(i).setLocked(true);
                    }
                }
            }
        }
コード例 #8
0
        /*Проверка разблокировки третьего места условной вершины*/
        private void checkUnLockPlaceFromCondition(VertexGraph condition)
        {
            //Поиск не заблокированного места.
            bool thereUnlock = false;

            for (int i = 0; i < 3; i++)
            {
                if (condition.getPlaceOutputLine(i).getLocked() == false)
                {
                    thereUnlock = true;
                    break;
                }
            }

            //Если есть не заблокированное место, то ищем место, которое могло быть заблокировано из-за того,
            //что из улсовной вершины может выходить только две линии.
            if (thereUnlock == true)
            {
                for (int i = 0; i < 3; i++)
                {
                    if ((condition.getPlaceOutputLine(i).getLocked() == true) && (condition.getPlaceOutputLine(i).getLine() == null))
                    {
                        condition.getPlaceOutputLine(i).setLocked(false);
                        break;
                    }
                }
            }
        }
コード例 #9
0
        //Создание условной вершины.
        private void buttonCreateCondition_Click(object sender, EventArgs e)
        {
            //Свойства добавляемого объекта.
            int id   = countID;
            int type = TYPE_OBJECT.VERTEX;

            Point[] aPointObject = new Point[5] {
                new Point(35, 0), new Point(70, 15), new Point(35, 30), new Point(0, 15), new Point(35, 0)
            };
            Point  pointText = new Point(20, 3);
            string text      = comboBoxCondition.Text;

            //Текст вершины.
            TextGraph textVertex = new TextGraph(0, TYPE_OBJECT.TEXT, pointText, text);

            textVertex.setVisibleContour(false);
            textVertex.setVisibleBrush(false);

            //Создание вершины.
            VertexGraph vertex = new VertexGraph(id, type, aPointObject, textVertex);

            vertex.setColorBrush(colorEmpty);
            vertex.setReactOutputPlaceOnCursor(false);

            //Добавление мест для линий.
            vertex.addPlaceInputLine(new PlaceForLine(0, TYPE_OBJECT.PLACE_FOR_LINE, vertex, new Point(35, 0), new Size(8, 8)));    //Место для соединения линии сверху.
            vertex.addPlaceOutputLine(new PlaceForLine(0, TYPE_OBJECT.PLACE_FOR_LINE, vertex, new Point(70, 15), new Size(8, 8)));  //Место для вывода линии справа.
            vertex.addPlaceOutputLine(new PlaceForLine(1, TYPE_OBJECT.PLACE_FOR_LINE, vertex, new Point(35, 30), new Size(8, 8)));  //Место для вывода линии снизу.
            vertex.addPlaceOutputLine(new PlaceForLine(2, TYPE_OBJECT.PLACE_FOR_LINE, vertex, new Point(0, 15), new Size(8, 8)));   //Место для вывода линии слева.

            //Добавление объекта в буфер созданного объекта, но еще не добавленного.
            bufferCreatedVertex = vertex;
        }
コード例 #10
0
    public void RemoveVertex(int vertice)
    {
        if (vertice >= vertices.Count)
        {
            return;
        }
        VertexGraph currentVert = vertices[vertice];

        for (int i = arcos.Count - 1; i >= 0; i--)
        {
            if (arcos[i].getVertex(0) == currentVert.index || arcos[i].getVertex(1) == currentVert.index)
            {
                vertices[arcos[i].getVertex(0)].RemoveNeighbour(arcos[i].getVertex(1));
                vertices[arcos[i].getVertex(1)].RemoveNeighbour(arcos[i].getVertex(0));

                //arcos[i].getVertex(0).RemoveNeighbour(arcos[i]);
                //arcos[i].getVertex(1).RemoveNeighbour(arcos[i]);
                arcos.Remove(arcos[i]);
            }
        }

        vertices.Remove(currentVert);
        DestroyImmediate(currentVert.vertex);
        for (int i = 0; i < vertices.Count; i++)
        {
            vertices[i].vertex.name = i.ToString();
            vertices[i].index       = i;
        }
        //UnityEditor.EditorUtility.SetDirty(this);
    }
コード例 #11
0
        public void FindNodeForEdge()
        {
            // Basic lookup tested in testAddVertexNode, only test failures here
            VertexGraph graph = new VertexGraph(9);

            // Empty graph
            var node = graph.FindEdge(vertex1, vertex2);

            Assert.IsNull(node);
            graph.AddNode(vertex1, vertex2);

            // Different hash
            node = graph.FindEdge(vertex3, vertex2);
            Assert.IsNull(node);

            // Hash collision
            node = graph.FindEdge(vertex1, vertex3);
            Assert.IsNull(node);

            graph.AddNode(vertex1, vertex4);

            // Hash collision, list iteration
            node = graph.FindEdge(vertex1, vertex3);
            Assert.IsNull(node);
            graph.Clear();
        }
コード例 #12
0
        public void RemoveVertexNode()
        {
            VertexGraph graph = new VertexGraph(9);

            // Straight removal
            var node    = graph.AddNode(vertex1, vertex2);
            var success = graph.RemoveNode(node);

            Assert.IsTrue(success);
            Assert.IsNull(graph.FindVertex(vertex1));
            Assert.AreEqual(0, graph.Size);

            // Remove end of list
            graph.AddNode(vertex1, vertex2);
            node    = graph.AddNode(vertex1, vertex3);
            success = graph.RemoveNode(node);

            Assert.IsTrue(success);
            Assert.IsNull(graph.FindEdge(vertex1, vertex3));
            Assert.AreEqual(1, graph.Size);

            // This removal is just cleanup
            node = graph.FindVertex(vertex1);
            Assert.IsTrue(graph.RemoveNode(node));

            // Remove beginning of list
            node = graph.AddNode(vertex1, vertex2);
            graph.AddNode(vertex1, vertex3);
            success = graph.RemoveNode(node);

            Assert.IsTrue(success);

            Assert.IsNull(graph.FindEdge(vertex1, vertex2));
            Assert.IsNotNull(graph.FindEdge(vertex1, vertex3));
            Assert.AreEqual(1, graph.Size);

            // This removal is just cleanup
            node = graph.FindVertex(vertex1);
            Assert.IsTrue(graph.RemoveNode(node));

            // Remove middle of list
            graph.AddNode(vertex1, vertex2);
            node = graph.AddNode(vertex1, vertex3);
            graph.AddNode(vertex1, vertex4);
            success = graph.RemoveNode(node);

            Assert.IsTrue(success);
            Assert.IsNull(graph.FindEdge(vertex1, vertex3));
            Assert.IsNotNull(graph.FindEdge(vertex1, vertex4));
            Assert.AreEqual(2, graph.Size);

            // Remove non-existent node
            node    = new VertexNode();
            success = graph.RemoveNode(node);
            Assert.IsFalse(success);

            Assert.AreEqual(2, graph.Size);
            graph.Clear();
        }
コード例 #13
0
        public void CanGetSizeTest()
        {
            VertexGraph graph = new VertexGraph();

            graph.AddVertex(new Vertex());
            graph.AddVertex(new Vertex());
            Assert.Equal(2, graph.Size());
        }
コード例 #14
0
 public void setPlayerNode(VertexGraph node)
 {
     if (playerNode == null || node.index != playerNode.index)
     {
         playerNode = node;
         Dijkstra(playerNode.index);
     }
 }
コード例 #15
0
        //Определение текста линии.
        private string getTextLine(VertexGraph vertexFrom)
        {
            //Если условная вершина, то выбор истинного или ложного перехода.
            if (isCondition(vertexFrom) == true)
            {
                bool isFirstTransition = true;

                for (int i = 0; i < 3; i++)
                {
                    if (vertexFrom.getPlaceOutputLine(i).getLine() != null)
                    {
                        if (vertexFrom.getPlaceOutputLine(i).getLine().getText() != null)
                        {
                            isFirstTransition = false; break;
                        }
                    }
                }

                //Если еще ни одна линия не проведена.
                if (isFirstTransition == true)
                {
                    var result = MessageBox.Show("Первый переход будет истинным?", "Выбор логического условия", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        return("+");
                    }
                    else
                    {
                        return("-");
                    }
                }
                //Если одна линия уже проведена.
                else
                {
                    //Определение условия перехода по уже созданному переходу.
                    for (int i = 0; i < 3; i++)
                    {
                        if (vertexFrom.getPlaceOutputLine(i).getLine() != null)
                        {
                            if (vertexFrom.getPlaceOutputLine(i).getLine().getText() != null)
                            {
                                if (vertexFrom.getPlaceOutputLine(i).getLine().getText().getText() == "+")
                                {
                                    return("-");
                                }
                                else
                                {
                                    return("+");
                                }
                            }
                        }
                    }
                }
            }

            //Если операторная вершина, то текста у линии нет.
            return("");
        }
コード例 #16
0
        public void SingleHex()
        {
            var set = new List <H3Index> {
                0x890dab6220bffff
            };
            VertexGraph graph = set.ToVertexGraph();

            Assert.AreEqual(6, graph.Size);
            graph.Clear();
        }
コード例 #17
0
        public void empty()
        {
            VertexGraph graph    = new VertexGraph(0, 0);
            int         numHexes = 0;
            var         set      = makeSet(null, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);

            Assert.True(graph.size == 0, "No edges added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #18
0
    public List <VertexGraph> getPathToPlayer(VertexGraph current) //FALTA meterlo en el player
    {
        List <VertexGraph> list = new List <VertexGraph>(0);

        while (current.index != playerNode.index)
        {
            current = vertices[padre[current.index]];
            list.Add(current);
        }

        return(list);
    }
コード例 #19
0
 //Проверка, является ли объект условием.
 public bool isCondition(ObjectGraph objectGraph)
 {
     if (objectGraph.getType() == TYPE_OBJECT.VERTEX)
     {
         VertexGraph vertex = (VertexGraph)objectGraph;
         if (vertex.getText() != null)
         {
             string nameVertex = vertex.getText().getText();
             return(algorithm.isCondition(nameVertex));
         }
     }
     return(false);
 }
コード例 #20
0
        public void CanAddEdgeTest()
        {
            VertexGraph graph       = new VertexGraph();
            Vertex      startVertex = new Vertex();
            Vertex      endVertex   = new Vertex();

            graph.AddVertex(startVertex);
            graph.AddVertex(endVertex);
            int weight = 5;

            graph.AddEdge(startVertex, endVertex, weight);
            Assert.Equal(startVertex, graph.AddEdge(startVertex, endVertex, weight));
        }
コード例 #21
0
        public void contiguous3()
        {
            VertexGraph graph = new VertexGraph(0, 0);
            var         hexes = new List <string> {
                "8928308288bffff", "892830828d7ffff", "8928308289bffff"
            };
            int numHexes = hexes.Count;
            var set      = makeSet(hexes, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);
            Assert.True(graph.size == 3 * 4, "All edges except 6 shared added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #22
0
        public void contiguous2distorted()
        {
            VertexGraph graph = new VertexGraph(0, 0);
            var         hexes = new List <string> {
                "894cc5365afffff", "894cc536537ffff"
            };
            int numHexes = hexes.Count;
            var set      = makeSet(hexes, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);
            Assert.True(graph.size == 12, "All edges except 2 shared added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #23
0
        public void singleHex()
        {
            VertexGraph   graph = new VertexGraph(0, 0);
            List <string> hexes = new List <string> {
                "890dab6220bffff"
            };

            int            numHexes = hexes.Count;
            List <H3Index> set      = makeSet(hexes, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);
            Assert.True(graph.size == 6, "All edges of one hex added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #24
0
        public void nonContiguous2()
        {
            VertexGraph   graph = new VertexGraph(0, 0);
            List <string> hexes = new List <string> {
                "8928308291bffff", "89283082943ffff"
            };
            int numHexes = hexes.Count;
            var set      = makeSet(hexes, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);
            Assert.True(graph.size == 12,
                        "All edges of two non-contiguous hexes added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #25
0
        public void vertexHashNegative()
        {
            int numBuckets = 10;

            Assert.True
            (
                VertexGraph._hashVertex(vertex5, 5, numBuckets) < numBuckets,
                "zero vertex hashes correctly"
            );
            Assert.True
            (
                VertexGraph._hashVertex(vertex6, 5, numBuckets) < numBuckets,
                "negative coordinates vertex hashes correctly"
            );
        }
コード例 #26
0
        public void firstVertexNode()
        {
            resetGeoCoords();
            VertexGraph graph = new VertexGraph(10, 9);

            VertexGraph.VertexNode node      = new VertexGraph.VertexNode();
            VertexGraph.VertexNode addedNode = new VertexGraph.VertexNode();

            node = VertexGraph.firstVertexNode(ref graph);
            Assert.Null(node, "No node found for empty graph");

            addedNode = VertexGraph.addVertexNode(ref graph, vertex1, vertex2);

            node = VertexGraph.firstVertexNode(ref graph);
            Assert.True(node == addedNode, "Node found");
        }
コード例 #27
0
        public void FirstVertexNode()
        {
            VertexGraph graph = new VertexGraph(9);

            var node = graph.FirstNode();

            Assert.IsNull(node);

            var addedNode = graph.AddNode(vertex1, vertex2);

            node = graph.FirstNode();
            Assert.IsNotNull(node);
            Assert.AreEqual(addedNode, node.Value);

            graph.Clear();
        }
コード例 #28
0
        public void hole()
        {
            VertexGraph graph = new VertexGraph(0, 0);
            var         hexes = new List <string> {
                "892830828c7ffff", "892830828d7ffff", "8928308289bffff",
                "89283082813ffff", "8928308288fffff", "89283082883ffff"
            };
            int numHexes = hexes.Count;
            var set      = makeSet(hexes, numHexes);

            Algos.h3SetToVertexGraph(ref set, numHexes, ref graph);
            Assert.True(graph.size == (6 * 3) + 6,
                        "All outer edges and inner hole edges added to graph");

            VertexGraph.destroyVertexGraph(ref graph);
        }
コード例 #29
0
        //Добавление вершины.
        private void addVertex()
        {
            //Добавление объекта в список объектов.
            aObjectGraph.Add(bufferCreatedVertex);
            countID++;

            //Завершение перемещения объекта для выбора начального места.
            originalBitmap = moveVertex.finish();

            //Отображение измененного слоя.
            pictureBoxGraph.Image = originalBitmap;                 //Отобразить на экране.
            detectorObject.setOriginalBitmap(originalBitmap);       //Изменение слоя в распознавателе объектов.

            //Удаление из списка еще не добавленных объектов.
            if (isOperator(bufferCreatedVertex) == true)
            {
                comboBoxOperator.Items.Remove(bufferCreatedVertex.getText().getText());
                //Если список пуст, то блокируем кнопку добавления.
                if (comboBoxOperator.Items.Count == 0)
                {
                    buttonCreateOperator.Enabled = false;
                }
                //Если список не пуст, то устанавливаем указатель на первый элемент в списке.
                else
                {
                    comboBoxOperator.SelectedIndex = 0;
                }
            }
            else if (isCondition(bufferCreatedVertex) == true)
            {
                comboBoxCondition.Items.Remove(bufferCreatedVertex.getText().getText());
                //Если список пуст, то блокируем кнопку добавления.
                if (comboBoxCondition.Items.Count == 0)
                {
                    buttonCreateCondition.Enabled = false;
                }
                //Если список не пуст, то устанавливаем указатель на первый элемент в списке.
                else
                {
                    comboBoxCondition.SelectedIndex = 0;
                }
            }

            //Очистка буфера.
            bufferCreatedVertex = null;
        }
コード例 #30
0
        public void CanGetAllNodesTest()
        {
            VertexGraph graph   = new VertexGraph();
            Vertex      vertexA = new Vertex();
            Vertex      vertexB = new Vertex();
            Vertex      vertexC = new Vertex();

            graph.AddVertex(vertexA);
            graph.AddVertex(vertexB);
            graph.AddVertex(vertexC);
            List <Vertex> list = new List <Vertex>()
            {
                vertexA, vertexB, vertexC
            };

            Assert.Equal(list, graph.GetNodes());
        }