コード例 #1
0
        public LPMinimumCostMatching(ISolver solver, IGraph graph, Func <Arc, double> cost,
                                     int minimumMatchingSize = 0, int maximumMatchingSize = int.MaxValue)
        {
            Graph = graph;
            Cost  = cost;
            MinimumMatchingSize = minimumMatchingSize;
            MaximumMatchingSize = maximumMatchingSize;

            OptimalSubgraph g = new OptimalSubgraph(Graph);

            g.MaxDegree   = x => 1.0;
            g.MinArcCount = MinimumMatchingSize;
            g.MaxArcCount = MaximumMatchingSize;
            OptimalSubgraph.CostFunction c = new OptimalSubgraph.CostFunction(cost: cost, objectiveWeight: 1);
            g.CostFunctions.Add(c);
            g.Run(solver);

            SolutionType = g.SolutionType;
            Debug.Assert(SolutionType != SolutionType.Unbounded);
            if (g.ResultGraph != null)
            {
                matching = new Matching(Graph);
                foreach (Arc arc in g.ResultGraph.Arcs())
                {
                    matching.Enable(arc, true);
                }
            }
            else
            {
                matching = null;
            }
        }
コード例 #2
0
        public LPMaximumMatching(ISolver solver, IGraph graph)
        {
            Graph = graph;

            OptimalSubgraph g = new OptimalSubgraph(Graph);

            g.MaxDegree      = x => 1.0;
            g.ArcCountWeight = -1.0;
            g.Run(solver);

            SolutionType = g.SolutionType;
            Debug.Assert(SolutionType != SolutionType.Unbounded);
            if (g.ResultGraph != null)
            {
                matching = new Matching(Graph);
                foreach (Arc arc in g.ResultGraph.Arcs())
                {
                    matching.Enable(arc, true);
                }
            }
            else
            {
                matching = null;
            }
        }