public void GenerateGraph_VerticesAndEdgeProbability_HasCorrectNumberOfVertices()
        {
            const int    numberOfVertices = 5;
            const double edgeProbability  = 0.5;

            var erdosRenyiModel = new ErdosRenyiModel(numberOfVertices, edgeProbability);
            var graph           = erdosRenyiModel.GenerateGraph();

            Assert.AreEqual(numberOfVertices, graph.Keys.Count);
        }
        public void GenerateGraph_VerticesAndEdges_HasCorrectNumberOfVertices()
        {
            const int numberOfVertices = 5;
            const int numberOfEdges    = 10;

            var erdosRenyiModel = new ErdosRenyiModel(numberOfVertices, numberOfEdges);
            var graph           = erdosRenyiModel.GenerateGraph();

            Assert.AreEqual(numberOfVertices, graph.Keys.Count);
        }
        private void Testing(ErdosRenyiModelEnum erdosRenyiModelEnum)
        {
            try
            {
                switch (erdosRenyiModelEnum)
                {
                case ErdosRenyiModelEnum.erdosRenyiModelCDividedByNLessThanOne:
                    stringBuilder.AppendLine(erdosRenyiModelEnum.ToString());
                    erdosRenyiModel = new ErdosRenyiModel(COUNTVERTICES, ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.cDividedByNLessThanOne);
                    graph           = erdosRenyiModel.GenerateGraph();

                    if (graph.GetRealCountVertices() != COUNTVERTICES)
                    {
                        throw new MyException.GraphException.GraphInvalidCountVerticesException("The number of vertices of generated graph is wrong!");
                    }

                    stringBuilder.AppendLine("OK");
                    break;

                case ErdosRenyiModelEnum.erdosRenyiModelCDividedByNMoreThanOne:
                    stringBuilder.AppendLine(erdosRenyiModelEnum.ToString());
                    erdosRenyiModel = new ErdosRenyiModel(COUNTVERTICES, ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.cDividedByNMoreThanOne);
                    graph           = erdosRenyiModel.GenerateGraph();

                    if (graph.GetRealCountVertices() != COUNTVERTICES)
                    {
                        throw new MyException.GraphException.GraphInvalidCountVerticesException("The number of vertices of generated graph is wrong!");
                    }

                    stringBuilder.AppendLine("OK");
                    break;

                case ErdosRenyiModelEnum.erdosRenyiModelCLogNDividedByN:
                    stringBuilder.AppendLine(erdosRenyiModelEnum.ToString());
                    erdosRenyiModel = new ErdosRenyiModel(COUNTVERTICES, ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.cLogNDividedByN);
                    graph           = erdosRenyiModel.GenerateGraph();

                    if (graph.GetRealCountVertices() != COUNTVERTICES)
                    {
                        throw new MyException.GraphException.GraphInvalidCountVerticesException("The number of vertices of generated graph is wrong!");
                    }

                    stringBuilder.AppendLine("OK");
                    break;

                case ErdosRenyiModelEnum.erdosRenyiModelNotAssigned:
                    stringBuilder.AppendLine(erdosRenyiModelEnum.ToString());
                    erdosRenyiModel = new ErdosRenyiModel(COUNTVERTICES, ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.notAssigned);
                    graph           = erdosRenyiModel.GenerateGraph();

                    if (erdosRenyiModel.GetErdosRenyiModelProbabilityEnum() == ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.notAssigned)
                    {
                        throw new MyException.GenerateGraphException.ErdosReneiModelChoosePNotAssigned();
                    }

                    if (graph.GetRealCountVertices() != COUNTVERTICES)
                    {
                        throw new MyException.GraphException.GraphInvalidCountVerticesException("The number of vertices of generated graph is wrong!");
                    }

                    stringBuilder.AppendLine("OK");
                    break;

                case ErdosRenyiModelEnum.invalidVerticesCount:
                    stringBuilder.AppendLine(erdosRenyiModelEnum.ToString());
                    erdosRenyiModel = new ErdosRenyiModel(0, ErdosRenyiModel.ErdosRenyiModelProbabilityEnum.notAssigned);
                    graph           = erdosRenyiModel.GenerateGraph();
                    break;

                default:
                    throw new MyException.TestsException.TestsMissingTestException();
                }
            }
            catch (Exception e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemple #4
0
        static int Main(string[] args)
        {
            XmlConfigurator.Configure();

            Action <Dictionary <Vertex, List <Edge> >, OptionsBase> exportAct = (graph, options) =>
            {
                IExportGraph exportFile = null;
                var          dataWriter = new FileWriter(options.ExportGraphFileName);
                if (options.ExportGraphFileType == GraphFileType.Dimacs)
                {
                    exportFile = new DimacsFileExport(dataWriter);
                }
                else if (options.ExportGraphFileType == GraphFileType.FullWeightedMetis)
                {
                    exportFile = new FullWeightedMetisFileExport(dataWriter);
                }
                else if (options.ExportGraphFileType == GraphFileType.UnweightedMetis)
                {
                    exportFile = new UnweightedMetisFileExport(dataWriter);
                }
                else if (options.ExportGraphFileType == GraphFileType.D3Json)
                {
                    exportFile = new D3JsonFileExport(dataWriter);
                }

                if (exportFile == null)
                {
                    throw new ApplicationException("The application does not support file export type.");
                }

                exportFile.ExportGraph(graph);
            };

            Func <RandomGraphOptions, Dictionary <Vertex, List <Edge> > > randomGraphFunc = options =>
            {
                IRandomGraph randomGraph = null;
                if (options.GraphAlgortiham == RandomGraphType.ErdosRenyiEdges)
                {
                    randomGraph = new ErdosRenyiModel(options.NumberOfVertices, options.NumberOfEdges);
                }
                //else if (options.GraphAlgortiham == RandomGraphType.ErdosRenyiPercent)
                //{
                //    randomGraph = new ErdosRenyiModel(int.Parse(args[1]), double.Parse(args[2]));
                //}

                if (randomGraph == null)
                {
                    throw new ApplicationException("The application does not support random graph model.");
                }

                var graph = randomGraph.GenerateGraph();
                return(graph);
            };

            Func <ConvertGraphOptions, Dictionary <Vertex, List <Edge> > > parseGraphFromFileFunc =
                options =>
            {
                var fileLoader = new FileLoader(options.InputGraphFileName);

                ParseGraphBase graphParser = null;
                if (options.ImportGraphFileType == GraphFileType.Dimacs)
                {
                    graphParser = new ParseDimacsGraph(fileLoader);
                }

                if (graphParser == null)
                {
                    throw new ApplicationException("The application does not support input graph model.");
                }

                var graph = graphParser.ParseGraph();
                return(graph);
            };

            var result   = Parser.Default.ParseArguments <RandomGraphOptions, ConvertGraphOptions>(args);
            var exitCode = result
                           .MapResult(
                (RandomGraphOptions options) =>
            {
                if (options.Verbose)
                {
                    System.Console.WriteLine("Filenames: {0}", 1);
                }
                else
                {
                    System.Console.WriteLine("Processing...");

                    var graph = randomGraphFunc(options);
                    exportAct(graph, options);
                }
                return(0);
            },
                (ConvertGraphOptions options) =>
            {
                var graph = parseGraphFromFileFunc(options);
                exportAct(graph, options);

                return(0);
            },
                errors => 1);

            return(exitCode);
        }