コード例 #1
0
        /**
         * {@inheritDoc}
         */
        public override E addEdge(V sourceVertex, V targetVertex)
        {
            assertVertexExist(sourceVertex);
            assertVertexExist(targetVertex);

            if (!allowingMultipleEdges && containsEdge(sourceVertex, targetVertex))
            {
                return(default(E));
            }

            if (!allowingLoops && sourceVertex.Equals(targetVertex))
            {
                throw new ArgumentException(LOOPS_NOT_ALLOWED);
            }

            E e = edgeFactory.createEdge(sourceVertex, targetVertex);

            if (containsEdge(e))
            { // this restriction should stay!
                return(default(E));
            }
            else
            {
                intrusiveEdgesSpecifics.add(e, sourceVertex, targetVertex);
                specifics.addEdgeToTouchingVertices(e);
                return(e);
            }
        }
コード例 #2
0
ファイル: Graphs.cs プロジェクト: happtim/tutorialDotNet
        /**
         * Creates a new edge and adds it to the specified graph similarly to the
         * {@link Graph#addEdge(Object, Object)} method.
         *
         * @param g the graph for which the edge to be added
         * @param sourceVertex source vertex of the edge
         * @param targetVertex target vertex of the edge
         * @param weight weight of the edge
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @return The newly created edge if added to the graph, otherwise <code>
         * null</code>.
         *
         * @see Graph#addEdge(Object, Object)
         */
        public static E addEdge <V, E>(Graph <V, E> g, V sourceVertex, V targetVertex, double weight)
        {
            EdgeFactory <V, E> ef = g.getEdgeFactory();
            E e = ef.createEdge(sourceVertex, targetVertex);

            // we first create the edge and set the weight to make sure that
            // listeners will see the correct weight upon addEdge.
            g.setEdgeWeight(e, weight);

            return(g.addEdge(sourceVertex, targetVertex, e) ? e : default(E));
        }
コード例 #3
0
        }         // ensure non-instantiability.

        /// <summary> Creates a new edge and adds it to the specified graph similarly to the
        /// {@link Graph#addEdge(Object, Object)} method.
        ///
        /// </summary>
        /// <param name="g">the graph for which the edge to be added.
        /// </param>
        /// <param name="sourceVertex">source vertex of the edge.
        /// </param>
        /// <param name="targetVertex">target vertex of the edge.
        /// </param>
        /// <param name="weight">weight of the edge.
        ///
        /// </param>
        /// <returns> The newly created edge if added to the graph, otherwise
        /// <code>null</code>.
        ///
        /// </returns>
        /// <seealso cref="Graph.addEdge(Object, Object)">
        /// </seealso>
        public static Edge addEdge(Graph g, System.Object sourceVertex, System.Object targetVertex, double weight)
        {
            EdgeFactory ef = g.EdgeFactory;
            Edge        e  = ef.createEdge(sourceVertex, targetVertex);

            // we first create the edge and set the weight to make sure that
            // listeners will see the correct weight upon addEdge.
            e.Weight = weight;

            return(g.addEdge(e)?e:null);
        }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();
            listBox.Items.Clear();
            listBox.ItemsSource = allProcesses;
            EdgeFactory factory = new EdgeFactory();

            Project project = new Project();
            Process A       = new Process()
            {
                Name = "1", Duration = new TimeSpan(4, 0, 0, 0), EarliestStart = new DateTime(1, 1, 2), EarliestEnd = new DateTime(1, 1, 5)
            };
            Process B = new Process()
            {
                Name = "2", Duration = new TimeSpan(2, 0, 0, 0), EarliestStart = new DateTime(1, 1, 2), EarliestEnd = new DateTime(1, 1, 3)
            };

            Process F = new Process()
            {
                Name = "6", Duration = new TimeSpan(8, 0, 0, 0)
            };
            Process G = new Process()
            {
                Name = "7", Duration = new TimeSpan(4, 0, 0, 0)
            };


            Process J = new Process()
            {
                Name = "10", Duration = new TimeSpan(16, 0, 0, 0)
            };
            Process K = new Process()
            {
                Name = "11", Duration = new TimeSpan(8, 0, 0, 0)
            };


            Process N = new Process()
            {
                Name = "14", Duration = new TimeSpan(12, 0, 0, 0)
            };


            allProcesses.Add(A);
            allProcesses.Add(B);
            allProcesses.Add(F);
            allProcesses.Add(G);
            allProcesses.Add(J);
            allProcesses.Add(K);
            allProcesses.Add(N);


            #region starting Processes
            Edge AF = factory.createEdge(A, F);
            A.Next.Add(AF);

            Edge BG = factory.createEdge(B, G);
            B.Next.Add(BG);

            project.RootProcesses.Add(A);
            project.RootProcesses.Add(B);
            #endregion



            #region regular Process Connections
            F.Previous.Add(AF);

            Edge FJ = factory.createEdge(F, J);
            F.Next.Add(FJ);
            J.Previous.Add(FJ);

            Edge JN = factory.createEdge(J, N);
            J.Next.Add(JN);
            N.Previous.Add(JN);

            G.Previous.Add(BG);

            Edge GK = factory.createEdge(G, K);
            G.Next.Add(GK);
            K.Previous.Add(GK);

            Edge KN = factory.createEdge(K, N);
            K.Next.Add(KN);
            N.Previous.Add(KN);


            #endregion

            project.CalculateAllTimes();
        }