示例#1
0
        static void Main(string[] args)
        {
            DateTime dt     = DateTime.Now;
            int      option = 0;

            if (args.Length != 2)
            {
                throw new ArgumentException(
                          "Wrong number of arguments!Please specify two paths for the first and second input graphs");
            }

            var   G1 = GraphLoader.LoadGraph(args[0]);
            var   G2 = GraphLoader.LoadGraph(args[1]);
            State s  = new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix);

            if (option == 0)
            {
                Console.Write("V Solution\n");
                SolutionV.McGregor(new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix), ref s);
            }
            else
            {
                Console.Write("V+E Solution\n");
                SolutionV.McGregor(new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix), ref s, 1);
            }

            //List<Edge> edges = s.correspondingEdges.Select(x => x.Item1).ToList();
            GraphLoader.WriteSummary(G1, G2, s.correspondingEdges,
                                     s.correspondingVerticles.Count(x => x.v1 != -1 && x.v2 != -1));
        }
        static void Main(string[] args)
        {
            string pathToFile1, pathToFile2;
            int    generationSize, generationCount;
            var    breakWhenScoreDrops = false;

            if (args.Length < 4)
            {
                throw new ArgumentException("Too few arguments");
            }
            if (!string.IsNullOrEmpty(args[0]) && !string.IsNullOrEmpty(args[1]))
            {
                pathToFile1 = args[0];
                pathToFile2 = args[1];
            }
            else
            {
                throw new ArgumentException("Empty path arguments");
            }

            if (int.TryParse(args[2], out var value1) && int.TryParse(args[3], out var value2))
            {
                generationSize  = value1;
                generationCount = value2;
            }
            else
            {
                throw new ArgumentException("Could not parse generation size or generation count");
            }

            if (args.Length == 5 && bool.TryParse(args[4], out var value))
            {
                breakWhenScoreDrops = value;
            }

            var g1 = GraphLoader.LoadGraph(pathToFile1);
            var g2 = GraphLoader.LoadGraph(pathToFile2);

            var watch = Stopwatch.StartNew();

            var algorithm = new GeneticAlgorithm(generationSize, generationCount, breakWhenScoreDrops);
            var solution  = algorithm.FindMaximalCommonSubgraph(g1, g2);

            Console.WriteLine(solution.ToString());
#if DEBUG
            Console.WriteLine($"{watch.ElapsedMilliseconds}ms, score={solution.Score}");
#endif
        }
示例#3
0
        private static bool Init(string[] args)
        {
            try
            {
                _graph = GraphLoader.LoadGraph(args[0]);
                int tmp;
                if (!int.TryParse(args[1], out tmp) || !_graph.Nodes.Contains(tmp))
                {
                    _error = "Given node value isn't an integer or doesn't exist in given graph";
                    return(false);
                }
                _startNode = tmp;

                _costs = new List <float>(_graph.Count);
                for (int i = 0; i < _graph.Count; i++)
                {
                    _costs.Add(MAX_WEIGHT);
                }
                _costs[_startNode] = 0;

                _edges = new List <Tuple <int, int, float> >();
                List <float?> nodeEdges;
                for (int i = 0; i < _graph.Count; i++)
                {
                    nodeEdges = _graph.Edges[i];
                    for (int j = 0; j < nodeEdges.Count; j++)
                    {
                        if (nodeEdges[j].HasValue)
                        {
                            _edges.Add(new Tuple <int, int, float>(i, j, nodeEdges[j].Value));
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                _error  = ex.Message + '\n';
                _error += ex.StackTrace;
                return(false);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            if (args.Length != 3 || (args[2] != "V" && args[2] != "E"))
            {
                throw new ArgumentException("Invalid arguments!");
            }

            var graphA = GraphLoader.LoadGraph(args[0]);
            var graphB = GraphLoader.LoadGraph(args[1]);

            Console.WriteLine();

            var modularGraph = new ModularGraph(graphA, graphB);
            var result       = modularGraph.LargestCliqueHeuristic(args[2] == "1");
            var edgesA       = graphA.Subgraph(result.Item1).Edges;
            var edgesB       = graphB.Subgraph(result.Item2).Edges;

            GraphLoader.WriteSummary(graphA, graphB, edgesA, edgesB, result.Item1.Count);
        }
示例#5
0
        static int Main(string[] args)
        {
            const string usageMessage = "Usage:\nepoxy <configuration json file>";

            if (args.Length != 1 || args[0] == "-h" || args[0] == "--help")
            {
                Console.Error.WriteLine(usageMessage);
                return(-1);
            }

            string configurationJsonFilePath = args[0];

            if (!File.Exists(configurationJsonFilePath))
            {
                Console.Error.WriteLine($"Configuration file '{configurationJsonFilePath}' does not exist.");

                if (!Path.IsPathRooted(configurationJsonFilePath))
                {
                    Console.Error.WriteLine($"Path appears to be relative and the current working directory is '{Directory.GetCurrentDirectory()}'.");
                }

                return(-2);
            }

            Configuration config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(configurationJsonFilePath));

            (bool configIsValid, string message) = config.Validate();
            if (!configIsValid)
            {
                if (!message.IsNullOrEmpty())
                {
                    Console.Error.WriteLine($"Invalid configuration: {message}");
                }

                return(-3);
            }

            Graph graph = GraphLoader.LoadGraph(Directory.EnumerateFiles(config.DoxygenXmlDirectory).Where(file => Path.GetExtension(file) == ".xml"));

            if (graph == null)
            {
                Console.Error.WriteLine("Failed to load C++ library definitions successfully.");
                return(-4);
            }

            foreach (BinderConfiguration binderConfig in config.Binders)
            {
                IBinder binder = BinderFactory.GetBinder(binderConfig);
                if (binder == null)
                {
                    Console.WriteLine($"Warning: language '{binderConfig.Language}' currently does not have a binder implemented-skipping.");
                    continue;
                }

                binder.GenerateNativeBindings(graph);
                binder.GenerateLanguageBindings(graph);
            }

            Console.WriteLine("SUCCESS");
            return(0);
        }