示例#1
0
        public void EdgeComparerEquals1_SameEdge_ShouldReturn_true()
        {
            var edge1    = new Edge <int>(0, 1);
            var comparer = new EdgeComparer();

            Assert.AreEqual(true, comparer.Equals(edge1, edge1));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="vertices">the coordinates of the vertices</param>
 public Trapezoidation(IReadOnlyList <Vertex> vertices, IPolygonSplitSink splitSink)
 {
     this.vertexToEdge = new Dictionary <int, TrapezoidEdge>();
     this.comparer     = new EdgeComparer(vertices);
     this.activeEdges  = new RedBlackTree <TrapezoidEdge>(this.comparer);
     this.splitSink    = splitSink;
 }
    List <Edge> KruskalMST(Graph g)
    {
        EdgeComparer ec       = new EdgeComparer();
        List <Edge>  allEdges = g.allEdges;

        allEdges.Sort(ec);

        DisjointSet ds = new DisjointSet();

        foreach (Vertex v in g.allVertex.Values)
        {
            ds.MakeSet(v.id);
        }

        List <Edge> mst = new List <Edge>();

        foreach (Edge e in allEdges)
        {
            int p1 = ds.FindSet(e.v1.id);
            int p2 = ds.FindSet(e.v2.id);

            if (p1 == p2)
            {
                continue;
            }

            mst.Add(e);
            ds.Union(p1, p2);
        }

        return(mst);
    }
        public async void SendApprovalNotification(IEnumerable <KeyResultArea> keyAreas)
        {
            string subject     = "Approve Key Result Area ";
            string message     = "has sumbitted one or more key result area, kindly review and act on it";
            string title       = "Key Result Area(KRA) For Approval";
            string htmlContent = "";
            string textContent = "";

            var comparer = EdgeComparer.Get <EmailObject>((x, y) => x.ReceiverEmailAddress == y.ReceiverEmailAddress);
            List <EmailObject> emailObj = keyAreas.Select(x => new EmailObject()
            {
                ReceiverEmailAddress = x.HodDetails.Email, ReceiverFullName = x.HodDetails.Name
            }).ToList();

            var distinctEmailObject = emailObj.Distinct(comparer).Select(x => x).ToList();
            var employee            = await GetEmployee(keyAreas.FirstOrDefault().EmployeeId);

            EmailDtoForMultiple emailDtos = new EmailDtoForMultiple()
            {
                PlainTextContent = textContent,
                HtmlContent      = htmlContent,
                EmailObjects     = distinctEmailObject
            };

            var result = sender.SendMultipleEmail(subject, employee.FullName, emailDtos, message, title);
        }
示例#5
0
    private Queue <Edge> mst = new Queue <Edge>(); // edges in MST



    public KruskalMST(EdgeWeightedGraph G)
    {
        // more efficient to build heap by passing array of edges

        EdgeComparer comparer = new EdgeComparer();
        MinPQ <Edge> pq       = new MinPQ <Edge>((Comparer <Edge>)comparer);

        foreach (Edge e in G.edges())
        {
            pq.insert(e);
        }

        // run greedy algorithm
        UF uf = new UF(G.V());

        while (!pq.isEmpty() && mst.size() < G.V() - 1)
        {
            Edge e = pq.delMin();
            int  v = e.either();
            int  w = e.other(v);
            if (!uf.connected(v, w))
            {                   // v-w does not create a cycle
                uf.union(v, w); // merge v and w components
                mst.Enqueue(e); // add edge e to mst
                weight += e.Weight();
            }
        }
    }
        public void EdgeComparerGetHashCode3_ShouldReturn_false()
        {
            var edge1    = new Edge <int>(1, 12);
            var edge2    = new Edge <int>(2, 6);
            var comparer = new EdgeComparer();

            Assert.AreNotEqual(comparer.GetHashCode(edge1), comparer.GetHashCode(edge2));
        }
        public void EdgeComparerGetHashCode2_ShouldReturn_true()
        {
            var edge1    = new Edge <int>(1, 13);
            var edge2    = new Edge <int>(1, 13);
            var comparer = new EdgeComparer();

            Assert.AreEqual(comparer.GetHashCode(edge1), comparer.GetHashCode(edge2));
        }
        public void EdgeComparerEquals3_ShouldReturn_false()
        {
            var edge1    = new Edge <int>(12, 1);
            var edge2    = new Edge <int>(6, 2);
            var comparer = new EdgeComparer();

            Assert.AreEqual(false, comparer.Equals(edge1, edge2));
        }
        public void EdgeComparerEquals_SourceAndTargetExchanged_ShouldReturn_true()
        {
            var edge1    = new Edge <int>(0, 1);
            var edge2    = new Edge <int>(1, 0);
            var comparer = new EdgeComparer();

            Assert.AreEqual(true, comparer.Equals(edge1, edge2));
        }
示例#10
0
        public void Sort()
        {
            var comparer = new EdgeComparer();

            for (var i = 0; i < scanlines.Length; i++)
            {
                scanlines[i]?.Sort(comparer);
            }
        }
        static Program()
        {
            EdgeService  = new EdgeService();
            GraphService = new GraphService(EdgeService);

            EdgeAdder    = new EdgeAdder();
            EdgeComparer = new EdgeComparer();

            Stopwatch = new Stopwatch();
        }
示例#12
0
    private MinPQ <Edge> pq;  // edges with one endpoint in tree

    public LazyPrimMST(EdgeWeightedGraph G)
    {
        mst = new Queue <Edge>();
        EdgeComparer    ec           = new EdgeComparer();
        Comparer <Edge> edgeComparer = (Comparer <Edge>)ec;

        pq     = new MinPQ <Edge>(edgeComparer);
        marked = new bool[G.V()];
        for (int v = 0; v < G.V(); v++)     // run Prim from all vertices to
        {
            if (!marked[v])
            {
                prim(G, v);                 // get a minimum spanning forest
            }
        }
    }
示例#13
0
 static EdgeComparer()
 {
     Default = new EdgeComparer();
 }
示例#14
0
    public void Start()
    {
        mesh                = GetComponent <MeshFilter>().mesh;
        vertices            = mesh.vertices;
        nodes               = new Node[vertices.Length];
        springs             = new List <Spring>();
        TriangulosOrdenados = new List <Edge>();
        for (int i = 0; i < vertices.Length; i++)
        {
            nodes[i] = new Node(vertices[i], Mass, dampingNode);

            foreach (GameObject fixer in fixers)
            {
                Collider Fixer_Box = fixer.GetComponent <Collider>();
                if (Fixer_Box.bounds.Contains(transform.TransformPoint(vertices[i])))
                {
                    nodes[i].Fixed = true;
                    break;
                }
            }
        }

        //int[] triangulos = mesh.triangles;
        for (int i = 0; i < mesh.triangles.Length; i = i + 3)
        {
            TriangulosOrdenados.Add(new Edge(mesh.triangles[i], mesh.triangles[i + 1], mesh.triangles[i + 2]));
            TriangulosOrdenados.Add(new Edge(mesh.triangles[i], mesh.triangles[i + 2], mesh.triangles[i + 1]));
            TriangulosOrdenados.Add(new Edge(mesh.triangles[i + 1], mesh.triangles[i + 2], mesh.triangles[i]));
        }

        EdgeComparer comparador = new EdgeComparer();

        TriangulosOrdenados.Sort(comparador);


        for (int i = 0; i < (TriangulosOrdenados.Count - 1); i++)
        {
            if (TriangulosOrdenados[i].vertexA == TriangulosOrdenados[i + 1].vertexA && TriangulosOrdenados[i].vertexB == TriangulosOrdenados[i + 1].vertexB)
            {
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexOther], nodes[TriangulosOrdenados[i + 1].vertexOther], StiffnessFlexion, dampingSpring));
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexOther], nodes[TriangulosOrdenados[i].vertexA], Stiffness, dampingSpring));
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexOther], nodes[TriangulosOrdenados[i].vertexB], Stiffness, dampingSpring));
            }

            else
            {
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexOther], nodes[TriangulosOrdenados[i].vertexA], Stiffness, dampingSpring));
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexOther], nodes[TriangulosOrdenados[i].vertexB], Stiffness, dampingSpring));
                springs.Add(new Spring(nodes[TriangulosOrdenados[i].vertexA], nodes[TriangulosOrdenados[i].vertexB], Stiffness, dampingSpring));
            }
        }

        foreach (Node node in nodes)
        {
            node.Manager = this;
        }

        foreach (Spring spring in springs)
        {
            spring.Manager = this;
        }
    }