Example #1
0
        public static Supergraph CreateSatsumaGraph(this Choosability.Graph g)
        {
            var satsumaGraph = new CustomGraph();

            var nodes = new Dictionary <int, Node>();

            foreach (var v in g.Vertices)
            {
                var node = satsumaGraph.AddNode();
                nodes[v] = node;
            }

            for (int i = 0; i < g.N; i++)
            {
                for (int j = i + 1; j < g.N; j++)
                {
                    if (g.Directed[i, j])
                    {
                        satsumaGraph.AddArc(nodes[i], nodes[j], Directedness.Directed);
                    }
                    else if (g.Directed[j, i])
                    {
                        satsumaGraph.AddArc(nodes[j], nodes[i], Directedness.Directed);
                    }
                    else if (g.Adjacent[i, j])
                    {
                        satsumaGraph.AddArc(nodes[i], nodes[j], Directedness.Undirected);
                    }
                }
            }

            return(satsumaGraph);
        }
Example #2
0
 private void CreateGraphArcs(NavigationNode[] navigationTransitions)
 {
     for (int i = 0; i < navigationTransitions.Length; i += 2)
     {
         Graph.AddArc(navigationTransitions[i].Node,
                      navigationTransitions[i + 1].Node,
                      Directedness.Undirected);
     }
 }
Example #3
0
        public override void Solve()
        {
            var pparser = new Pparser(FpatIn);
            int ccity, cwizard;

            pparser.Fetch(out ccity, out cwizard);
            var rgcity   = pparser.FetchN <Nod>(ccity);
            var rgwizard = pparser.FetchN <Nod>(cwizard);

            var graph       = new CustomGraph();
            var mpnodByinod = new Dictionary <long, Nod>();

            foreach (var wizard in rgwizard)
            {
                wizard.kind = Kind.Wizard;
                wizard.node = graph.AddNode();
                mpnodByinod[wizard.node.Id] = wizard;
            }

            foreach (var city in rgcity)
            {
                city.kind = Kind.City;
                city.node = graph.AddNode();
                mpnodByinod[city.node.Id] = city;
            }

            foreach (var wizard in rgwizard)
            {
                foreach (var city in rgcity)
                {
                    if (Dist(wizard, city) <= 50)
                    {
                        graph.AddArc(wizard.node, city.node, Directedness.Directed);
                    }
                }
            }

            var mm = new MaximumMatching(graph, node => mpnodByinod[node.Id].kind == Kind.Wizard);

            mm.Run();

            using (Output)
            {
                Solwrt.WriteLine(mm.Matching.ArcCount());
            }
        }