/// <summary>
        /// Initializes a new instance of the <see cref="GraphBalancerAlgorithm{TVertex,TEdge}"/> class.
        /// </summary>
        /// <param name="visitedGraph">Graph to visit.</param>
        /// <param name="source">Flow source vertex.</param>
        /// <param name="sink">Flow sink vertex.</param>
        /// <param name="vertexFactory">Vertex factory method.</param>
        /// <param name="edgeFactory">Edge factory method.</param>
        public GraphBalancerAlgorithm(
            [NotNull] IMutableBidirectionalGraph <TVertex, TEdge> visitedGraph,
            [NotNull] TVertex source,
            [NotNull] TVertex sink,
            [NotNull] VertexFactory <TVertex> vertexFactory,
            [NotNull] EdgeFactory <TVertex, TEdge> edgeFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (sink == null)
            {
                throw new ArgumentNullException(nameof(sink));
            }

            VisitedGraph  = visitedGraph ?? throw new ArgumentNullException(nameof(visitedGraph));
            VertexFactory = vertexFactory ?? throw new ArgumentNullException(nameof(vertexFactory));
            EdgeFactory   = edgeFactory ?? throw new ArgumentNullException(nameof(edgeFactory));

            if (!VisitedGraph.ContainsVertex(source))
            {
                throw new ArgumentException("Source must be in the graph", nameof(source));
            }
            if (!VisitedGraph.ContainsVertex(sink))
            {
                throw new ArgumentException("Sink must be in the graph", nameof(sink));
            }
            Source = source;
            Sink   = sink;

            foreach (TEdge edge in VisitedGraph.Edges)
            {
                // Setting capacities = u(e) = +infinity
                Capacities.Add(edge, double.MaxValue);

                // Setting preflow = l(e) = 1
                _preFlow.Add(edge, 1);
            }
        }
Ejemplo n.º 2
0
        public void AddCapacity(CapacityType capacityType)
        {
            if (this.MaxNumberOfCapacities > this.Capacities.Count)
            {
                if (!PossesCapacity(capacityType))
                {
                    Capacity capacity = new Capacity(capacityType);
                    Capacities.Add(capacity);

                    if (capacityType == CapacityType.WeaponMastery)
                    {
                        while (this.WeaponMastery == WeaponTypes.None)
                        {
                            this.WeaponMastery = GlobalFunction.RandomEnumValue <WeaponTypes>();
                        }
                    }
                }
            }
            else
            {
                throw new MaxNumberOfCapacitiesReached(GlobalTranslator.Instance.Translator.ProvideValue("TooManyCapacities") + " (" + MaxNumberOfCapacities + ")");
            }
        }