Beispiel #1
0
        public GraphList <Group> GetUserGroups(string userId, string query = "")
        {
            var g = new GraphList <Group>()
            {
                Values = new List <Group>()
            };

            var result = SendAADGraphRequest($"/users/{userId}/memberOf", query);
            var groups = JsonConvert.DeserializeObject <GraphList <Group> >(result);

            if (groups?.Values != null)
            {
                g.Values.AddRange(groups.Values);
            }
            while (!string.IsNullOrEmpty(groups?.ODataNextLink))
            {
                groups = GetNextGroups(groups.ODataNextLink);
                if (groups?.Values != null && groups.Values.Count > 0)
                {
                    g.Values.AddRange(groups.Values);
                }
            }
            g.ODataNextLink = groups?.ODataNextLink;
            return(g);
        }
Beispiel #2
0
 public static void PrintProps <T, TAdjacencyList, TEdge>([NotNull] this GraphList <T, TAdjacencyList, TEdge> thisValue)
     where TAdjacencyList : class, ICollection <TEdge>
 {
     Console.WriteLine();
     Console.WriteLine($"{Yellow("Order:")} {Underline(thisValue.Count.ToString())}.");
     Console.WriteLine($"{Yellow("Size:")} {Underline(thisValue.GetSize().ToString())}.");
 }
Beispiel #3
0
        /// <summary>
        ///     Видалити ребро з найбільшим показником Betweenness
        /// </summary>
        /// <param name="pTempCS"></param>
        /// <returns></returns>
        private Graph RemoveMaxEdgeBetweenness(GraphList pTempCS)
        {
            if (_edgeBetweenness == null || _edgeBetweenness.Count == 0)
            {
                return(null);
            }
            var max = _edgeBetweenness.Max(n => n.Value);
            var e   = _edgeBetweenness.Where(n => Math.Abs(n.Value - max) < 1e-6).ToArray()[0].Key;

            _graph.Edges.Remove(e);

            e.VertexOut.AdjacencyEdges.Remove(e);
            e.VertexIn.AdjacencyEdges.Remove(e);

            e.VertexOut.GetAdjacencyVertices().Remove(e.VertexIn);
            e.VertexIn.GetAdjacencyVertices().Remove(e.VertexOut);

            _edgeBetweenness.Remove(e);

            foreach (var subgraph in pTempCS)
            {
                if (subgraph.Vertices.Contains(e.VertexOut))
                {
                    return(subgraph);
                }
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Return the name (key) of the next unvisited vertex
        /// </summary>
        /// <param name="name">Name/Key of the Dictionary item to look for</param>
        /// <returns>Vertex of the next, previously unvisited vertex</returns>
        public Vertex GetAdjacentUnvisited(String name)
        {
            bool   foundVisited        = false;
            int    indexOfVertexInList = 0;
            int    incrementor         = 0;
            Vertex returnValue         = null;

            if (GraphDictionary.ContainsKey(name))                                          // Test if the key exists in the dictionary
            {
                indexOfVertexInList = GraphList.IndexOf(GraphDictionary[name]);             // Get the index of the vertex

                do                                                                          // Loop through vertices until one is found that
                {                                                                           // wasn't found before
                    if ((adjMatrix[indexOfVertexInList, incrementor] != 0) &&
                        (!GraphList[incrementor].Visited) &&
                        (!VisitedList.Contains(GraphList[incrementor])))
                    {
                        returnValue = GraphList[incrementor];                               // Return the next vertex
                        GraphList[incrementor].Visited = true;                              // Set it's "visited" property to true
                        foundVisited = true;                                                // Set the "found" variable to true to break the loop
                    }

                    incrementor++;                                                          // do/while incrementor
                } while ((!foundVisited) && (incrementor < adjMatrix.GetLength(1)));        // Once we find a vertex, or get to the end of the matrix, break
            }

            return(returnValue);
        }
Beispiel #5
0
        public static void bfs(GraphList g, int vertex)
        {
            BreadthFirstSearch search = new BreadthFirstSearch(g, vertex);

            for (int v = 0; v < g.V(); v++)
            {
                Console.Write(vertex + " To " + v + ": ");
                if (search.HasPathTo(v))
                {
                    foreach (int x in search.PathTo(v))
                    {
                        if (x == vertex)
                        {
                            Console.Write(x);
                        }
                        else
                        {
                            Console.Write("-" + x);
                        }
                    }
                }
                else
                {
                    Console.Write("No path");
                }

                Console.WriteLine();
            }
        }
Beispiel #6
0
        public static void SaveList(GraphList list, string path)
        {
            //throw new NotImplementedException();
            StreamWriter sw = new StreamWriter(path);

            for (int i = 0; i < list.NodesNr; i++)
            {
                foreach (var item in list.GetConnections(i))
                {
                    if (item < 10)
                    {
                        sw.Write("00" + item);
                    }
                    else if (item < 100)
                    {
                        sw.Write("0" + item);
                    }
                    else
                    {
                        sw.Write(item);
                    }
                    sw.Write(';');
                }
                sw.Write('\n');
            }
            sw.Close();
        }
Beispiel #7
0
        public Graph2DPlotter(string name)
            : base(name, Docking.Fill, new Graph2DPlotterStyle())
        {
            // this.Cursor = Cursors.Cross;
            Font = SummerGUIWindow.CurrentContext.FontManager.DefaultFont;

            m_CenterPoint.X = 0;
            m_CenterPoint.Y = 0;

            PlotMargin        = 8;
            PointRadius       = 6f;
            DefaultCurveWidth = 3f;
            AxisWidth         = 1.5f;

            xRange = 20;
            yRange = 20;
            ZoomX  = 1.0;
            ZoomY  = 1.0;

            Graphs   = new GraphList();
            CanFocus = true;

            //timer_catch = new System.Windows.Forms.Timer();
            //timer_catch.Interval = 50;
            //timer_catch.Tick += new EventHandler(timer_catch_Tick);

            //Thread caretThread = new Thread(new ThreadStart(ShowCaret));
            //caretThread.Start();
        }
Beispiel #8
0
            public ConnectionInfoViewModel(ObservablePhotonPeer peer)
            {
                this.MaxSize     = "0B";
                this.MaxSent     = "0B";
                this.MaxReceived = "0B";
                this.Peer        = new WeakReference(peer);
                this.GraphList   = new CircularBuffer <UniRx.Tuple <int, int> >(lastWidth);

                var interval = TimeSpan.FromMilliseconds(100);

                var send        = peer.ObserveSendOpCustom().Select(x => GetSize(x)).Buffer(interval, Scheduler.ThreadPool);
                var sendReceive = peer.ObserveOperationResponse().Select(x => GetSize(x.OperationResponse.Parameters)).Buffer(interval, Scheduler.ThreadPool);
                var receive     = peer.ObserveReceiveEventData().Select(x => GetSize(x.Parameters)).Buffer(interval, Scheduler.ThreadPool);

                subscription = Observable.Zip(send, sendReceive, receive, (x, y, z) => Tuple.Create(x.Sum(), y.Sum() + z.Sum()))
                               .Subscribe(x =>
                {
                    lock (GraphListLock)
                    {
                        TotalSent     += x.Item1;
                        TotalReceived += x.Item2;
                        GraphList.Enqueue(x);
                    }
                });
            }
Beispiel #9
0
        /// <summary>
        /// Znajduje sciezke eulera
        /// Wymagany graf spojny
        /// Szukamy sciezki eulera z pktu "node"
        /// </summary>
        /// <param name="graph">Graf</param>
        /// <param name="node">Wezel poczatkowy ( moze byc podany dowolny patrz "sciezka eulera")</param>
        /// <returns>
        /// lista, w ktorej elemety sa posortowane zgodnie z kolejnoscia w sciezce wezel startowy/koncowy wystepuje na poczatku i koncu listy
        /// Zwroci null kiedy graf nie ma sciezki eulera => nie jest eulerowski
        /// </returns>
        public static List <int> EulerianPath(GraphMatrix graph, int node = 0)
        {
            GraphList temp = Converter.ConvertToList(graph);

            for (int i = 0; i < temp.NodesNr; i++)
            {
                if (temp.GetConnections(i).Count % 2 != 0)
                {
                    return(null);
                }
            }
            List <Tuple <int, int> > path = new List <Tuple <int, int> >();

            if (!Eul(temp, path, node, graph.ConnectionCount))
            {
                return(null);
            }
            List <int> rp = new List <int>();

            for (int i = 0; i < path.Count; i++)
            {
                rp.Add(path[i].Item1);
            }
            rp.Add(node);//powrot do poczatku
            return(rp);
        }
Beispiel #10
0
        /// <summary>
        /// Minimum spanning tree
        /// Spojnosc wymagana
        /// </summary>
        /// <param name="from"></param>
        /// <returns>Graphmatrix being tree</returns>
        public static GraphMatrix Prim(GraphMatrix from)
        {
            GraphList  help    = from;
            List <int> visited = new List <int>();//visited nodes

            visited.Add(0);
            GraphList tree = new GraphList(from.NodesNr);

            for (int i = 0; i < tree.NodesNr - 1; i++)                              //n-1 operation to make tree
            {
                Tuple <int, int, int> temp = new Tuple <int, int, int>(0, 0, 1000); //(skad, dokad, waga)
                for (int j = 0; j < visited.Count; j++)                             //search in visited nodes
                {
                    for (int k = 0; k < help.GetConnections(visited[j]).Count; k++) //search all branches in nodes
                    {
                        if (visited.Contains(help.GetConnections(visited[j])[k]))   //if we don't seek in visited
                        {
                            continue;
                        }
                        if (from.getWeight(visited[j], help.GetConnections(visited[j])[k]) < temp.Item3)
                        {
                            temp = new Tuple <int, int, int>(visited[j], help.GetConnections(visited[j])[k], from.getWeight(visited[j], help.GetConnections(visited[j])[k]));
                        }
                    }
                }
                tree.MakeConnection(temp.Item1, temp.Item2);
                tree.setWeight(temp.Item1, temp.Item2, temp.Item3);
                tree.setWeight(temp.Item2, temp.Item1, temp.Item3);
                visited.Add(temp.Item2);
            }
            return(tree);
        }
Beispiel #11
0
        private void pool_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "gui_config")
            {
                Dictionary <string, string> gui_config = Helpers.GetGuiConfig((IXenObject)sender);
                string uuid = Helpers.GetUuid(XenObject);

                foreach (string key in gui_config.Keys)
                {
                    if (!Palette.OtherConfigUUIDRegex.IsMatch(key) || !key.Contains(uuid))
                    {
                        continue;
                    }

                    string value = gui_config[key];
                    int    argb;
                    if (!Int32.TryParse(value, out argb))
                    {
                        continue;
                    }

                    string[] strs = key.Split('.');

                    // just set the color, we dont care what it is
                    Palette.SetCustomColor(Palette.GetUuid(strs[strs.Length - 1], XenObject), Color.FromArgb(argb));
                }

                Program.Invoke(this, () =>
                {
                    GraphList.LoadGraphs(XenObject);
                    RefreshAll();
                });
            }
        }
Beispiel #12
0
 private void Button_Генерировать(object sender, RoutedEventArgs e)
 {
     try
     {
         //СохранитьНастройки();
         if (App.Модель.IsBusy)
         {
             return;
         }
         App.Модель.IsBusy = true;
         GraphList.BeginInit();
         districtsGrid.BeginInit();
         narydsGrid.BeginInit();
         var wor = new BackgroundWorker();
         wor.DoWork             += (o, args) => App.Модель.GenerateEvents();
         wor.RunWorkerCompleted += (o, args) =>
         {
             ОбновитьВсё(null, null);
             GraphList.EndInit();
             districtsGrid.EndInit();
             narydsGrid.EndInit();
             App.Модель.IsBusy = false;
             wor.Dispose();
         };
         wor.RunWorkerAsync();
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("{0}\n{1}", ex.Message, ex.StackTrace), "Исключение");
     }
 }
Beispiel #13
0
        /// <summary>
        /// Знаходить вагу перерізу
        /// </summary>
        /// <param name="graphs"></param>
        /// <param name="original"></param>
        /// <returns></returns>
        public int CalculateG(GraphList graphs, Graph original)
        {
            var g = 0;

            foreach (var subgraph in graphs)
            {
                foreach (var v1 in subgraph.Vertices)
                {
                    var tmp = original.FindNode(v1.Label, false);
                    foreach (var v2 in original.Vertices)
                    {
                        var e = original.FindEdge(tmp, v2);
                        if (e != null)
                        {
                            var v = subgraph.FindNode(v2.Label, false);
                            if (v == null)
                            {
                                g += e.Weight;
                            }
                        }
                    }
                }
            }
            return(g / 2);
        }
Beispiel #14
0
 private void Button_Очистить(object sender, RoutedEventArgs e)
 {
     GraphList.BeginInit();
     App.Модель.ClearEvents();
     ОбновитьВсё(null, null);
     GraphList.EndInit();
 }
Beispiel #15
0
        public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph)
        {
            InitializeComponent();
            tableLayoutPanel1.Visible = false;

            this.graphList = graphList;
            isNew          = (designedGraph == null);
            if (isNew)
            {
                this.designedGraph = new DesignedGraph();
                // Generate an unique suggested name for the graph
                if (graphList != null)
                {
                    this.designedGraph.DisplayName = Helpers.MakeUniqueName(Messages.GRAPH_NAME, graphList.DisplayNames);
                }
                base.Text = Messages.GRAPHS_NEW_TITLE;
            }
            else
            {
                this.designedGraph = new DesignedGraph(designedGraph);
                base.Text          = string.Format(Messages.GRAPHS_DETAILS_TITLE, this.designedGraph.DisplayName);
                SaveButton.Text    = Messages.OK;
            }
            ActiveControl         = GraphNameTextBox;
            GraphNameTextBox.Text = this.designedGraph.DisplayName;
            EnableControls();
        }
Beispiel #16
0
        public static GraphMatrixInc ConvertToMatrixInc(GraphList input)
        {
            GraphList from = new GraphList(1);

            from.Set(input);
            int sumc = 0;

            for (int i = 0; i < from.NodesNr; i++)
            {
                sumc += from.CountElem(i);
            }
            sumc = sumc / 2;
            GraphMatrixInc q = new GraphMatrixInc(from.NodesNr, sumc);
            int            c = 0;

            for (int i = 0; i < from.NodesNr; i++)//pobiera po kolei elementy, dodaje do matrixinc i usuwa z listy
            {
                for (int j = 0; j < from.NodesNr; j++)
                {
                    if (from.GetConnection(i, j))
                    {
                        q.MakeConnection(i, j, c);
                        c++;
                        from.RemoveConnection(i, j);
                    }
                    q.setWeight(i, j, input.getWeight(i, j));
                }
            }
            return(q);
        }
Beispiel #17
0
 private void pool_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "gui_config")
     {
         Program.Invoke(this, () => GraphList.LoadGraphs(XenObject));
     }
 }
Beispiel #18
0
        /// <summary>
        /// Видалити ребро з найбільшим показником Betweenness
        /// </summary>
        /// <param name="pTempCS"></param>
        /// <returns></returns>
        private Graph RemoveMaxEdgeBetweenness(GraphList pTempCS)
        {
            if (edgeBetweenness == null || edgeBetweenness.Count == 0)
            {
                return(null);
            }
            double max = edgeBetweenness.Max(n => n.Value);
            Edge   e   = edgeBetweenness.Where(n => Math.Abs(n.Value - max) < 1e-6).ToArray()[0].Key;

            graph.Edges.Remove(e);

            e.VertexOut.AdjacencyEdges.Remove(e);
            e.VertexIn.AdjacencyEdges.Remove(e);

            e.VertexOut.GetAdjacencyVertices().Remove(e.VertexIn);
            e.VertexIn.GetAdjacencyVertices().Remove(e.VertexOut);

            WriteLog(" - Remove: (" + e.VertexOut.Label + ", " + e.VertexIn.Label + ")");

            edgeBetweenness.Remove(e);

            foreach (Graph subgraph in pTempCS)
            {
                if (subgraph.Vertices.Contains(e.VertexOut))
                {
                    return(subgraph);
                }
            }
            return(null);
        }
Beispiel #19
0
 protected override void CleanupManagedResources()
 {
     if (Graphs != null)
     {
         Graphs.Clear();
         Graphs = null;
     }
     base.CleanupManagedResources();
 }
Beispiel #20
0
 internal DepthFirstEnumerator([NotNull] GraphList <T> graph, T root)
 {
     _graph   = graph;
     _version = _graph._version;
     _root    = root;
     _current = default(T);
     _started = _hasValue = false;
     _done    = _graph.Count == 0 || _root == null;
     _visited = _done ? null : new HashSet <T>(graph.Comparer);
     _stack   = _done ? null : new Stack <T>();
 }
Beispiel #21
0
 /// <summary>
 /// przeszukiwanie grafu w glab operacje dokonujemy na liscie
 /// </summary>
 /// <param name="x">Graf ktory przeszukujemy</param>
 /// <param name="e">element w ktorym jestesmy</param>
 /// <param name="z">referencyna lista do zapisywania wierzcholkow spojnych</param>
 private static void rek(GraphList x, int e, List <int> z)//rekurencyjne przeszukiwanie grafu
 {
     for (int i = 0; i < x.GetConnections(e).Count; i++)
     {
         if (!z.Contains(x.GetConnections(e)[i]))
         {
             z.Add(x.GetConnections(e)[i]);
             rek(x, x.GetConnections(e)[i], z);
         }
     }
 }
Beispiel #22
0
        public override Problem FindCommunityStructure(Graph pGraph)
        {
            DateTime start = DateTime.UtcNow;
            Problem  p     = new Problem();

            p.Graph     = pGraph;
            p.Algorithm = Algorithm.KernighanLin;
            _graph      = pGraph.Clone();
            GraphList graphList;

            // начальное разбиение
            graphList = StartPartition(pGraph);
            while (IsAllFixed(_graph.Vertices) == false)
            {
                Dictionary <Vertex, int> Dv = D(graphList);
                GraphList graphlist1        = CountGrowth(Dv, graphList);
                if (graphlist1 == null)
                {
                    continue;
                }
                foreach (var sublist in graphlist1)
                {
                    foreach (var node1 in sublist.Vertices)
                    {
                        Console.Write(node1.Label);
                        Console.Write(' ');
                    }
                }
            }

            foreach (var g in graphList)
            {
                foreach (var v1 in g.Vertices)
                {
                    foreach (var v2 in g.Vertices)
                    {
                        Edge e = pGraph.FindEdge(v1, v2);
                        if (e == null)
                        {
                            continue;
                        }
                        g.CreateLink(e.VertexOut, e.VertexIn, e.Weight);
                        g.Edges.Add(e);
                    }
                }
            }
            DateTime end = DateTime.UtcNow;

            p.ExecutionTime = (end - start).Milliseconds;
            p.G             = CalculateG(graphList, pGraph);
            p.GraphList     = graphList;
            return(p);
        }
Beispiel #23
0
 private void SaveGraphs(ActionBase sender)
 {
     Program.Invoke(Program.MainWindow, delegate
     {
         var action = sender as GetDataSourcesAction;
         if (action != null)
         {
             var dataSources = DataSourceItemList.BuildList(action.IXenObject, action.DataSources);
             GraphList.SaveGraphs(dataSources);
         }
     });
 }
Beispiel #24
0
        private void Dfs(GraphList g, int v)
        {
            _visited[v] = true;

            foreach (var u in g.Adj(v))
            {
                if (!_visited[u])
                {
                    _edgeTo[u] = v;
                    Dfs(g, u);
                }
            }
        }
Beispiel #25
0
        public DepthFirstSearch(GraphList g, int source)
        {
            _visited = new bool[g.V()];
            _edgeTo  = new int[g.V()];
            _source  = source;

            for (int i = 0; i < _edgeTo.Length; ++i)
            {
                _edgeTo[i] = -1;
            }

            Dfs(g, source);
        }
Beispiel #26
0
        public static void DisplayGraph(GraphList g)
        {
            Console.WriteLine("{0} verticies, {1} edges", g.V(), g.E());

            for (int i = 0; i < g.V(); ++i)
            {
                Console.Write("{0}: ", i);
                foreach (var u in g.Adj(i))
                {
                    Console.Write("{0} ", u);
                }
                Console.WriteLine();
            }
        }
Beispiel #27
0
        public GraphList FindCommunityStructure(Graph pGraph)
        {
            graph = pGraph.Clone();
            GraphList graphList;

            // начальное разбиение

            graphList = StartPartition(pGraph);

            while (IsAllFixed(graph.Vertices) == false)
            {
                Dictionary <Vertex, int> Dv = D(graphList);
                GraphList graphlist1        = CountGrowth(Dv, graphList);
                if (graphlist1 == null)
                {
                    continue;
                }
                //Exchange(graphList);

                foreach (var sublist in graphlist1)
                {
                    foreach (var node1 in sublist.Vertices)
                    {
                        Console.Write(node1.Label);
                        Console.Write(' ');
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }

            foreach (var g in graphList)
            {
                foreach (var v1 in g.Vertices)
                {
                    foreach (var v2 in g.Vertices)
                    {
                        Edge e = pGraph.FindEdge(v1, v2);
                        if (e == null)
                        {
                            continue;
                        }
                        g.CreateLink(e.VertexOut, e.VertexIn, e.Weight);
                        g.Edges.Add(e);
                    }
                }
            }
            return(graphList);
        }
Beispiel #28
0
 private void DeleteGraph()
 {
     using (ThreeButtonDialog dlog = new WarningDialog(string.Format(Messages.DELETE_GRAPH_MESSAGE, GraphList.SelectedGraph.DisplayName.EscapeAmpersands()),
                                                       ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo))
     {
         if (dlog.ShowDialog(this) == DialogResult.Yes)
         {
             if (GraphList.AuthorizedRole)
             {
                 GraphList.DeleteGraph(GraphList.SelectedGraph);
                 GraphList.LoadDataSources(SaveGraphs);
             }
         }
     }
 }
Beispiel #29
0
        private void MoveGraphDown()
        {
            if (XenObject == null)
            {
                return;
            }

            int index = GraphList.SelectedGraphIndex;

            if (GraphList.AuthorizedRole)
            {
                GraphList.ExchangeGraphs(index, index + 1);
                GraphList.SaveGraphs(null);
            }
        }
Beispiel #30
0
 private void RestoreDefaultGraphs()
 {
     using (ThreeButtonDialog dlog = new WarningDialog(Messages.GRAPHS_RESTORE_DEFAULT_MESSAGE,
                                                       ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo))
     {
         if (dlog.ShowDialog(this) == DialogResult.Yes)
         {
             if (GraphList.AuthorizedRole)
             {
                 GraphList.RestoreDefaultGraphs();
                 GraphList.LoadDataSources(SaveGraphs);
             }
         }
     }
 }