bool savepath(vertex D, vertex d)
    {
        vertex temp = D;

        while (temp != d)
        {
            if (temp == null || temp.pass == null)
            {
                return(false);
            }
            if (!OpenVertex.Contains(temp))
            {
                OpenVertex.Add(temp);
            }
            foreach (path p in temp.paths_connection)
            {
                if (p.connection.Contains(temp) && p.connection.Contains(temp.pass))
                {
                    if (!OpenPath.Contains(p))
                    {
                        OpenPath.Add(p);
                    }
                }
            }
            temp = temp.pass;
        }
        OpenVertex.Add(d);
        return(true);
    }
示例#2
0
        static void solve(int v, int e)
        {
            vessels  = new int[451];
            vertices = new vertex[451];
            edges    = new edge[900];
            cliques  = new List <clique> [451];

            for (int i = 0; i < v; i++)
            {
                vessels[i + 1]  = Int32.Parse(Console.ReadLine());
                vertices[i + 1] = new vertex {
                    id = i + 1
                };
            }

            for (int i = 0; i < e; i++)
            {
                var s_e = Console.ReadLine().Split(' ');
                edges[i] = new edge {
                    s = Int32.Parse(s_e[0]), e = Int32.Parse(s_e[1])
                };

                vertices[edges[i].s].edges.Add(edges[i]);
                vertices[edges[i].e].edges.Add(edges[i]);
            }

            // Create all cliques of size 1
            cliques[1] = new List <clique>();
            for (int i = 1; i <= v; i++)
            {
                cliques[1].Add(new clique(i));
            }

            // Find all cliques in the graph
            for (int i = 1; i <= v; i++)
            {
                if (cliques[i] != null && cliques[i].Count > 0)
                {
                    doslow(i);
                }
            }

            // Find max loot
            var maxloot = 0;

            for (int i = 1; i <= v; i++)
            {
                if (cliques[i] == null || cliques[i].Count == 0)
                {
                    continue;
                }
                var max = cliques[i].Max(c => c.loot);
                if (maxloot < max)
                {
                    maxloot = max;
                }
            }

            output("" + maxloot);
        }
    bool BFS(vertex s, vertex t, List <vertex> notAvailable)
    {
        Queue <vertex> next = new Queue <vertex>();

        next.Enqueue(s);
        s.visited = true;
        while (next.Count != 0)
        {
            vertex v = next.Dequeue();
            foreach (vertex w in v.connection)
            {
                if (w == t)
                {
                    w.pass = v;
                    return(true);
                }
                else if (!w.visited && !notAvailable.Contains(w))
                {
                    next.Enqueue(w);
                    w.visited = true;
                    w.pass    = v;
                }
            }
        }
        return(false);
    }
示例#4
0
    public Bend(int ia, int ib, int ic, int id, vertex a, vertex b, vertex c, vertex d)
    {
        indexV1 = ia;
        indexV2 = ib;
        indexV3 = ic;
        indexV4 = id;
        v1      = a;
        v2      = b;
        v3      = c;
        v4      = d;
        Vector3 V  = v3.transform.position - v1.transform.position;
        Vector3 W  = v2.transform.position - v1.transform.position;
        float   Nx = (V.y * W.z) - (V.z * W.y);
        float   Ny = (V.z * W.x) - (V.x * W.z);
        float   Nz = (V.x * W.y) - (V.y * W.x);

        n1 = new Vector3(Nx, Ny, Nz);
        n1.Normalize();

        V  = v2.transform.position - v1.transform.position;
        W  = v4.transform.position - v1.transform.position;
        Nx = (V.y * W.z) - (V.z * W.y);
        Ny = (V.z * W.x) - (V.x * W.z);
        Nz = (V.x * W.y) - (V.y * W.x);
        n2 = new Vector3(Nx, Ny, Nz);
        n2.Normalize();
        this.d       = Vector3.Dot(n1, n2);
        initialAngle = Mathf.Acos(this.d);
    }
        public List <vertex> getNeighborhood(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                Console.WriteLine(String.Format("Solitacao da vizinhanca do vertice {0}", V.Name));
                using (var client = getServerOf(V.Name.ToString())) {
                    if (client != null)
                    {
                        return(client.getNeighborhood(V));
                    }
                }

                try {
                    var edges = this.getEdges(V).ToList();
                    if (!edges.Any())
                    {
                        return(new List <vertex>());
                    }

                    var neighborhood = new List <vertex>();
                    foreach (edge e in edges)
                    {
                        neighborhood.Add(this.readV(e.V2));
                    }

                    return(neighborhood);
                } catch (Exception e) {
                    throw e;
                }
            }
            return(null);
        }
        public bool createVertex(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                Console.WriteLine(String.Format("Solitacao de criacao do vertice {0}", V.Name));
                Console.WriteLine(string.Join("--", this.servers.Keys));
                using (var client = getServerOf(V.Name.ToString())) {
                    if (client != null)
                    {
                        return(client.createVertex(V));
                    }
                }

                MUTEX_V.WaitOne();
                if (this.g.V.Exists(v => v.Name == V.Name))
                {
                    throw new Thrift.VertexAlreadyExists();
                }

                this.requestRaftServer(string.Format("createVertex({0}, {1}, {2}, {3});", V.Name, V.Color, V.Description, V.Weight));

                this.g.V.Add(V);
                bool result = this.g.V.Exists(v => v.Name == V.Name);

                MUTEX_V.ReleaseMutex();
                return(result);
            }

            return(false);
        }
    public void ComputeNormals()
    {
        foreach (DictionaryEntry di in objects)
        {
            obj_type o = (obj_type)(di.Value);

            for (int i = 0; i < o.polygons_qty; i++)
            {
                o.polygon[i].normal = normals(o.vertex[o.polygon[i].c].point, o.vertex[o.polygon[i].b].point, o.vertex[o.polygon[i].a].point);
            }

            for (int i = 0; i < o.vertices_qty; i++)
            {
                vertex temp = new vertex();
                for (int j = 0; j < o.polygons_qty; j++)
                {
                    if (o.polygon[j].a == i || o.polygon[j].b == i || o.polygon[j].c == i)
                    {
                        temp = _3dsMath.sum(temp, o.polygon[j].normal);
                    }
                }
                //temp = o.polygon[j].normal;
                o.vertex[i].normal = _3dsMath.normalize(temp);
            }
        }
    }
    void setUpPath()
    {
        while (NotConnectedDoors.Count > 0)
        {
            List <vertex> CantMatch = new List <vertex>();

            vertex s = NotConnectedDoors[Random.Range(0, NotConnectedDoors.Count - 1)];
            vertex t = randomDoor(s, CantMatch);

            int errorCount = 0;
            while (!BFS(s, t, empty) && errorCount <= 8)
            {
                CantMatch.Add(t);
                resetvisited();
                t = randomDoor(s, CantMatch);
                errorCount++;
                if (errorCount == 8)
                {
                    setUpPathSuccess = false;
                    return;
                }
            }

            CantMatch = new List <vertex>();
            NotConnectedDoors.Remove(s);
            // if (NotConnectedDoors.Contains(t))
            // {
            //     NotConnectedDoors.Remove(t);
            // }
            savepath(t, s);
            resetvisited();
        }
        setUpPathSuccess = true;
    }
        /* the Euler algorithm */

        public void shuffle1(char[] s, int l, int k)
        {
            int i, n_lets;

            s_ = s;
            l_ = l;
            k_ = k;
            if (k_ >= l_ || k_ <= 1) /* two special cases */
            {
                return;
            }

            /* use hashtable to find distinct vertices */
            n_lets     = l_ - k_ + 2; /* number of (k-1)-lets */
            n_vertices = 0;
            hinit(n_lets);
            for (i = 0; i < n_lets; i++)
            {
                hinsert(i);
            }
            root     = entries[n_lets - 1].i_vertices; /* the last let */
            vertices = new vertex[n_vertices];
            for (i = 0; i < n_vertices; i++)
            {
                vertices[i] = new vertex();
            }

            /* set i_sequence and n_indices for each vertex */
            for (i = 0; i < n_lets; i++)
            { /* for each let */
                hentry ev = entries[i];
                vertex v  = vertices[ev.i_vertices];

                v.i_sequence = ev.i_sequence;
                if (i < n_lets - 1) /* not the last let */
                {
                    v.n_indices++;
                }
            }

            /* allocate indices for each vertex */
            for (i = 0; i < n_vertices; i++)
            { /* for each vertex */
                vertex v = vertices[i];

                v.indices = new int[v.n_indices];
            }

            /* populate indices for each vertex */
            for (i = 0; i < n_lets - 1; i++)
            { /* for each edge */
                hentry eu = entries[i];
                hentry ev = entries[i + 1];
                vertex u  = vertices[eu.i_vertices];

                u.indices[u.i_indices++] = ev.i_vertices;
            }
            hcleanup();
        }
示例#10
0
            public List <vertex> graphconst(string mapnom)
            {
                List <vertex>       listofpoints = new List <vertex>();
                List <weightededge> listofedgs   = new List <weightededge>();

                FileStream   fs = new FileStream(mapnom, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);

                using (StreamReader reader = File.OpenText(mapnom))
                {
                    int count = Int32.Parse(sr.ReadLine());
                    int a     = count;
                    reader.ReadLine();
                    for (int i = 0; i < count; i++)
                    {
                        vertex   p     = new vertex();
                        string   text  = reader.ReadLine();
                        string[] bitss = text.Split(' ');
                        p.index = int.Parse(bitss[0]);
                        p.index++;
                        p.x = float.Parse(bitss[1]);
                        p.y = float.Parse(bitss[2]);
                        listofpoints.Add(p);
                    }

                    int countE = Int32.Parse(reader.ReadLine());
                    for (int i = 0; i < countE; i++)
                    {
                        weightededge edge  = new weightededge();
                        string       textt = reader.ReadLine();
                        string[]     bits  = textt.Split(' ');
                        edge.start = int.Parse(bits[0]);
                        edge.start++;

                        edge.end = int.Parse(bits[1]);
                        edge.end++;

                        edge.distance = float.Parse(bits[2]);
                        edge.speed    = int.Parse(bits[3]);
                        edge.timecost = edge.distance / edge.speed;
                        listofedgs.Add(edge);
                    }

                    for (int i = 0; i < listofedgs.Count(); i++)
                    {
                        int s = listofedgs[i].start;
                        int d = listofedgs[i].end;


                        nieghbours n  = new nieghbours(d, listofedgs[i]);
                        nieghbours n2 = new nieghbours(s, listofedgs[i]);

                        listofpoints[s - 1].nieghbourr.Add(n);
                        listofpoints[d - 1].nieghbourr.Add(n2);
                    }

                    return(listofpoints);
                }
            }
示例#11
0
 public Stretch(int ia, int ib, vertex a, vertex b)
 {
     indexV1 = ia;
     indexV2 = ib;
     v1      = a;
     v2      = b;
     l0      = (v1.transform.position - v2.transform.position).magnitude;
 }
示例#12
0
 void build(int nmax = 1000)
 {
     t = new vertex[nmax + 1];
     //for(int i = 0; i < nmax + 1; i++)
     //{
     //    t[i] = new vertex();
     //}
 }
示例#13
0
 public bool contributes(vertex v)
 {
     if (vertices.FirstOrDefault(vertex => vertex == v.id) == default(int))
     {
         return(false);
     }
     return(true);
 }
    public static vertex dif(vertex v1, vertex v2)
    {
        vertex v = new vertex();

        v.x = v1.x - v2.x;
        v.y = v1.y - v2.y;
        v.z = v1.z - v2.z;
        return(v);
    }
    public static vertex cross(vertex v1, vertex v2)
    {
        vertex v = new vertex();

        v.x = v1.y * v2.z - v1.z * v2.y;
        v.y = v1.z * v2.x - v1.x * v2.z;
        v.z = v1.x * v2.y - v1.y * v2.x;
        return(v);
    }
示例#16
0
 public clique(int[] vs, vertex v)
 {
     vertices = new int[vs.Length + 1];
     for (int i = 0; i < vs.Length; i++)
     {
         vertices[i] = vs[i];
     }
     vertices[vs.Length] = v.id;
 }
    public static vertex sum(vertex v1, vertex v2)
    {
        vertex v = new vertex();

        v.x = v1.x + v2.x;
        v.y = v1.y + v2.y;
        v.z = v1.z + v2.z;
        return(v);
    }
示例#18
0
 public void Reset()
 {
     connection = new List <vertex>();
     foreach (vertex v in oldConnection)
     {
         connection.Add(v);
     }
     pass = null;
 }
 int GetIndex(vertex v)
 {
     for (int i = 0; i < vertices.Count; i++)
     {
         if (VertexEquals(vertices[i], v))
         {
             return(i);
         }
     }
     return(-1);
 }
    private vertex normals(vertex v1, vertex v2, vertex v3)
    {
        vertex d1, d2, norm;

        d1 = _3dsMath.dif(v2, v1);
        d2 = _3dsMath.dif(v3, v1);

        norm = _3dsMath.cross(d1, d2);

        norm = _3dsMath.normalize(norm);

        return(norm);
    }
 bool VertexEquals(vertex a, vertex b)
 {
     if (a.x == b.x)
     {
         if (a.y == b.y)
         {
             if (a.z == b.z)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#22
0
    public void GetPolygonTree(Mesh mesh)
    {
        Dictionary <normal, List <vertex> > PolygonTree = new Dictionary <normal, List <vertex> >();

        this.mesh = mesh;
        Vector3[] vertices = mesh.vertices;
        Vector3[] normals  = mesh.normals;

        int i;

        for (i = 0; i < normals.Length; i++)
        {
            if (!normal.ContainKey(PolygonTree, normals[i]))
            {
                PolygonTree.Add(new normal(normals[i], PolygonTree.Keys.Count), new List <vertex>());
            }
        }

        RealVertices = new List <vertex>();
        for (i = 0; i < vertices.Length; i++)
        {
            vertex v = vertex.vertexInList(RealVertices, vertices[i]);
            if (v == null)
            {
                RealVertices.Add(new vertex(vertices[i], RealVertices.Count));
                RealVertices[RealVertices.Count - 1].indexes = new List <int>();
                RealVertices[RealVertices.Count - 1].indexes.Add(i);
            }
            else
            {
                RealVertices[v.iReal].indexes.Add(i);
            }
        }


        vertex vertice; normal key;

        for (i = 0; i < vertices.Length; i++)
        {
            key = normal.TakeKey(PolygonTree, normals[i]);
            if (key != null)
            {
                vertice = vertex.vertexInList(RealVertices, vertices[i]);
                PolygonTree[key].Add(_realVertices[vertice.iReal]);
            }
        }

        _polygonTree = PolygonTree;
    }
    vertex randomVertex(List <vertex> pickFromHere)
    {
        if (pickFromHere.Count == 0)
        {
            return(null);
        }
        vertex ans = pickFromHere[Random.Range(0, pickFromHere.Count - 1)];

        pickFromHere.Remove(ans);
        foreach (vertex v in ans.connection)
        {
            pickFromHere.Remove(v);
        }
        return(ans);
    }
        public bool copyVertex(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                MUTEX_V.WaitOne();

                this.requestRaftServer(string.Format("createVertex({0}, {1}, {2}, {3});", V.Name, V.Color, V.Description, V.Weight));

                this.g.V.Add(V);
                MUTEX_V.ReleaseMutex();

                return(true);
            }
            return(false);
        }
示例#25
0
        /* here are parametric rules written as part of the ruleSet.
         * these are compiled at runtime into a .dll indicated in the
         * App.config file. */
        #region Parametric Recognition Rules

        /* Parametric recognition rules receive as input:
         * 1. the left hand side of the rule (L)
         * 2. the entire host graph (host)
         * 3. the location of the nodes in the host that L matches to (locatedNodes).
         * 4. the location of the arcs in the host that L matches to (locatedArcs). */
        #endregion


        #region Parametric Application Rules

        /* Parametric application rules receive as input:
         * 1. the location designGraph indicating the nodes&arcs of host that match with L (Lmapping)
         * 2. the entire host graph (host)
         * 3. the location of the nodes in the host that R matches to (Rmapping).
         * 4. the parameters chosen by an agent for instantiating elements of Rmapping or host (parameters). */

        /* This is APPLY for the rule entitled: swirlRule1  */
        public designGraph slopeOfNewEdge(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            edge   oldEdge    = (edge)Rmapping.arcs[0];
            vertex oldVertex0 = (vertex)Rmapping.nodes[0];
            vertex oldVertex1 = (vertex)Rmapping.nodes[1];
            double newAngle   = System.Math.Atan2((oldVertex1.y - oldVertex0.y), (oldVertex1.x - oldVertex0.x)) - 0.4;
            double newLength  = 1.05 * oldEdge.length;
            vertex newVertex  = (vertex)Rmapping.nodes[2];

            newVertex.x       = oldVertex1.x + newLength * System.Math.Cos(newAngle);
            newVertex.screenX = (float)newVertex.x;
            newVertex.y       = oldVertex1.y + newLength * System.Math.Sin(newAngle);
            newVertex.screenY = (float)newVertex.y;

            return(host);
        }
    public static vertex normalize(vertex v)
    {
        vertex nv = new vertex();
        float  l  = (float)(Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));

        if (l != 0.0)
        {
            nv.x = v.x / l;
            nv.y = v.y / l;
            nv.z = v.z / l;
        }
        else
        {
            nv = v;
        }
        return(nv);
    }
 public bool VertContains(vertex v)
 {
     foreach (vertex vert in this.vertices)
     {
         if (vert.x == v.x)
         {
             if (vert.y == v.y)
             {
                 if (vert.z == v.z)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
示例#28
0
        private static string Setup(string pic1, string pic2, string pic3)
        {
            try {
                vBuffer = new VertexBuffer(typeof(vertex), 4, DXMain.device, Usage.WriteOnly, vertex.format, Pool.Default);
                vertex[] verts=(vertex[])vBuffer.Lock(0, LockFlags.None);
                verts[0]=new vertex(-000.5f, -000.5f, 0, 1, 0, 0);
                verts[1]=new vertex(-000.5f, +1023.5f, 0, 1, 0, 1);
                verts[2]=new vertex(+1023.5f, -000.5f, 0, 1, 1, 0);
                verts[3]=new vertex(+1023.5f, +1023.5f, 0, 1, 1, 1);
                vBuffer.Unlock();
            } catch {
                return "Unable to create vertex buffer";
            }

            try {
                DXMain.device.SetStreamSource(0, vBuffer, 0, 64);
                DXMain.device.VertexFormat=vertex.format;
                DXMain.device.Indices=null;
                DXMain.device.RenderState.CullMode = Cull.None;
            } catch {
                return "Unable to set device state";
            }

            try {
                thisFrame = TextureLoader.FromFile(DXMain.device, pic1 == null ? Statics.runDir + "\\mge3\\preview.bmp" : pic1,
                    1024, 1024, 1, Usage.RenderTarget, DXMain.format, Pool.Default, Filter.Linear, Filter.Linear, 0);
                depthFrame = TextureLoader.FromFile(DXMain.device, pic3 == null ? Statics.runDir + "\\mge3\\depth.bmp" : pic3,
                    1024, 1024, 1, Usage.RenderTarget, DXMain.format, Pool.Default, Filter.Linear, Filter.Linear, 0);
                lastShader = TextureLoader.FromFile(DXMain.device, pic1 == null ? Statics.runDir + "\\mge3\\preview.bmp" : pic1,
                                    1024, 1024, 1, Usage.RenderTarget, DXMain.format, Pool.Default, Filter.Linear, Filter.Linear, 0);
                lastPass = new Texture(DXMain.device, 1024, 1024, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                //**/lastFrame = TextureLoader.FromFile(DXMain.device, pic2 == null ? Statics.runDir + "\\mge3\\preview.bmp" : pic2,
                //**/    1024, 1024, 1, Usage.RenderTarget, DXMain.format, Pool.Default, Filter.Linear, Filter.Linear, 0);

                if(thisFrame==null||lastPass==null||lastShader==null||depthFrame==null) throw new ApplicationException();

                thisFrameSurface = thisFrame.GetSurfaceLevel(0);
                lastShaderSurface = lastShader.GetSurfaceLevel(0);
                lastPassSurface = lastPass.GetSurfaceLevel(0);
                //**/lastFrameSurface = lastFrame.GetSurfaceLevel(0);
            } catch {
                return "Unable to create the required textures";
            }

            basetime = DateTime.Now.Ticks;
            return null;
        }
示例#29
0
        private void updateVB()
        {
            DataStream data = g_pVB.Lock(0, DS * Marshal.SizeOf(typeof(vertex)), LockFlags.None);
            data.Position = 0;

            for (int i = 0; i < DS; i++)
            {
                vertex v = new vertex();
                v.x = g_particles[i].x;
                v.y = g_particles[i].y;
                v.z = 0.0f;
                v.c = 0xff00ff00;

                data.Write<vertex>(v);
            }
            g_pVB.Unlock();
        }
示例#30
0
 public vertex GetVertex(UInt16 index, ref BinaryReader VertexData)
 {
     vertex v = new vertex();
     if (VertexData != null)
     {
         if (VertexData.BaseStream == null)
         {
             Queue.Push("VertexData is NULL (GetVertex)");
             return v;
         }
         VertexData.BaseStream.Seek(index * stride, SeekOrigin.Begin);
         //Queue.Push("Stride = ");
         //Queue.Push(stride.ToString());
         v.x = VertexData.ReadSingle();
         v.y = VertexData.ReadSingle();
         v.z = VertexData.ReadSingle();
     }
     return v;
 }
示例#31
0
 public bool VertContains(vertex v)
 {
     foreach (vertex vert in this.vertices)
     {
         if (vert.x == v.x)
             if (vert.y == v.y)
                 if (vert.z == v.z)
                     return true;
     }
     return false;
 }
示例#32
0
 int GetIndex(vertex v)
 {
     for (int i = 0; i < vertices.Count; i++)
     {
         if (VertexEquals(vertices[i], v))
             return i;
     }
     return -1;
 }
示例#33
0
 bool VertexEquals(vertex a, vertex b)
 {
     if (a.x == b.x)
         if (a.y == b.y)
             if (a.z == b.z)
                 return true;
     return false;
 }
示例#34
0
 public static vertex sum(vertex v1, vertex v2)
 {
     vertex v = new vertex();
         v.x = v1.x + v2.x;
         v.y = v1.y + v2.y;
         v.z = v1.z + v2.z;
         return v;
 }
示例#35
0
 public edge(vertex P1, vertex P2)
 {
     p1 = P1; p2 = P2;
 }
示例#36
0
 public static vertex dif(vertex v1, vertex v2)
 {
     vertex v = new vertex();
         v.x = v1.x - v2.x;
         v.y = v1.y - v2.y;
         v.z = v1.z - v2.z;
         return v;
 }
示例#37
0
 public static vertex normalize(vertex v)
 {
     vertex nv = new vertex();
         float l = (float)(Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));
         if (l != 0.0)
         {
             nv.x = v.x / l;
             nv.y = v.y / l;
             nv.z = v.z / l;
         }
         else
             nv = v;
         return nv;
 }
示例#38
0
 public static vertex cross(vertex v1, vertex v2)
 {
     vertex v = new vertex();
         v.x = v1.y * v2.z - v1.z * v2.y;
         v.y = v1.z * v2.x - v1.x * v2.z;
         v.z = v1.x * v2.y - v1.y * v2.x;
         return v;
 }
示例#39
0
    private vertex normals(vertex v1, vertex v2, vertex v3)
    {
        vertex d1, d2, norm;

            d1 = _3dsMath.dif(v2, v1);
            d2 = _3dsMath.dif(v3, v1);

            norm = _3dsMath.cross(d1, d2);

            norm = _3dsMath.normalize(norm);

            return norm;
    }
示例#40
0
    public void ComputeNormals()
    {
        foreach (DictionaryEntry di in objects)
            {
                obj_type o = (obj_type)(di.Value);

                for (int i = 0; i < o.polygons_qty; i++)
                    o.polygon[i].normal = normals(o.vertex[o.polygon[i].c].point, o.vertex[o.polygon[i].b].point, o.vertex[o.polygon[i].a].point);

                for (int i = 0; i < o.vertices_qty; i++)
                {
                    vertex temp = new vertex();
                    for (int j = 0; j < o.polygons_qty; j++)
                        if (o.polygon[j].a == i || o.polygon[j].b == i || o.polygon[j].c == i)
                            temp = _3dsMath.sum(temp, o.polygon[j].normal);
                            //temp = o.polygon[j].normal;
                    o.vertex[i].normal = _3dsMath.normalize(temp);
                }
            }
    }
        public List <edge> getEdges(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                Console.WriteLine(String.Format("Solitacao das arestas do vertice {0}", V.Name));
                using (var client = getServerOf(V.Name.ToString())) {
                    if (client != null)
                    {
                        return(client.getEdges(V));
                    }
                }
                try {
                    readV(V.Name);

                    MUTEX_E.WaitOne();
                    var E = this.g.E.Where(edge => edge.V1 == V.Name).ToList();

                    MUTEX_E.ReleaseMutex();
                    return(E);
                } catch (Exception e) {
                    throw e;
                }
            }
            return(null);
        }
        public bool deleteVertex(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                Console.WriteLine(String.Format("Solitacao de exclusao do vertice {0}", V.Name));
                using (var client = getServerOf(V.Name.ToString())) {
                    if (client != null)
                    {
                        return(client.deleteVertex(V));
                    }
                }

                MUTEX_V.WaitOne();
                if (!this.g.V.Exists(v => v.Name == V.Name))
                {
                    MUTEX_V.ReleaseMutex();
                    throw new Thrift.VertexDontExists();
                }

                this.requestRaftServer(string.Format("deleteVertex({0});", V.Name));


                this.g.V.RemoveAll(v => v.Name == V.Name);
                bool result = this.g.E.RemoveAll(edge => edge.V1 == V.Name || edge.V2 == V.Name) == 1;

                MUTEX_V.ReleaseMutex();
                return(result);
            }
            return(false);
        }
        public bool updateVertex(vertex V)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)
            {
                Console.WriteLine(String.Format("Solitacao de atualização do vertice {0}", V.Name));
                using (var client = getServerOf(V.Name.ToString())) {
                    if (client != null)
                    {
                        return(client.updateVertex(V));
                    }
                }

                MUTEX_V.WaitOne();
                foreach (vertex v in this.g.V)
                {
                    if (v.Equals(V))
                    {
                        this.requestRaftServer(string.Format("updateVertex({0}, {1}, {2}, {3});", V.Name, V.Color, V.Description, V.Weight));


                        v.Color       = V.Color;
                        v.Description = V.Description;
                        v.Weight      = V.Weight;

                        MUTEX_V.ReleaseMutex();
                        return(true);
                    }
                }

                MUTEX_V.ReleaseMutex();
                throw new VertexDontExists();
            }

            return(false);
        }