Пример #1
0
        public ActionResult Create(GraphMatrixModel graphModel)
        {
            var graphJsonModel = new GraphJsonModel();

            Session["currentGraph"] = graphModel.Data;

            try
            {
                Session["paths"] = CalculatePath(graphModel.Data);
            }
            catch (NegativeCyclesException)
            {
                ModelState.AddModelError("negativeCyclesException", "Граф имеет циклы с отрицательным весом");
                return(View(graphModel));
            }

            for (var i = 0; i < graphModel.Data.Length; i++)
            {
                graphJsonModel.Nodes.Add(new Node(i, i.ToString()));
                for (var j = 0; j < graphModel.Data.Length; j++)
                {
                    if (graphModel.Data[i][j].HasValue)
                    {
                        if (!graphJsonModel.Edges.Any(x => x.from == j && x.to == i && x.ves == graphModel.Data[i][j].Value))
                        {
                            var edge = new Edge
                            {
                                from   = i,
                                to     = j,
                                ves    = graphModel.Data[i][j].Value,
                                arrows = (graphModel.Data[i][j] == graphModel.Data[j][i]) ? "to, from" : "to"
                            };

                            graphJsonModel.Edges.Add(edge);
                        }
                    }
                }
            }

            return(View("Index", graphJsonModel));
        }
Пример #2
0
        public ActionResult Create()
        {
            const int n = 3;

            GraphMatrixModel model = new GraphMatrixModel();

            if (Session["currentGraph"] == null)
            {
                model.Data = new int?[n][];
                for (var i = 0; i < n; i++)
                {
                    model.Data[i] = new int?[n];
                }
            }
            else
            {
                model.Data = (int?[][])Session["currentGraph"];
            }

            return(View(model));
        }