コード例 #1
0
 public void EachEdge(EdgeAction del)
 {
     foreach (Connection e in graph.Connections)
     {
         del(e, GetSpring(e));
     }
 }
コード例 #2
0
        protected virtual void GenerateSpanningTree(CancellationToken cancellationToken)
        {
            SpanningTree = new BidirectionalGraph <TVertex, Edge <TVertex> >(false);
            SpanningTree.AddVertexRange(VisitedGraph.Vertices.OrderBy(v => VisitedGraph.InDegree(v)));

            EdgeAction <TVertex, TEdge> action = e =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                SpanningTree.AddEdge(new Edge <TVertex>(e.Source, e.Target));
            };

            switch (Parameters.SpanningTreeGeneration)
            {
            case SpanningTreeGeneration.BFS:
                var bfsAlgo = new BreadthFirstSearchAlgorithm <TVertex, TEdge>(VisitedGraph);
                bfsAlgo.TreeEdge += action;
                bfsAlgo.Compute();
                break;

            case SpanningTreeGeneration.DFS:
                var dfsAlgo = new DepthFirstSearchAlgorithm <TVertex, TEdge>(VisitedGraph);
                dfsAlgo.TreeEdge           += action;
                dfsAlgo.ForwardOrCrossEdge += action;
                dfsAlgo.Compute();
                break;
            }
        }
コード例 #3
0
 public void EachEdge(EdgeAction del)
 {
     foreach (var e in Graph.Edges)
     {
         del(e, GetSpring(e));
     }
 }
コード例 #4
0
 public MovingSprite(Texture2D texture, Vector2 position, SpriteEffects effects,
                     double timeBetweenUpdates, Vector2 speed, EdgeAction edge)
     : base(texture, position, effects, timeBetweenUpdates)
 {
     this.spd  = speed;
     this.edge = edge;
 }
コード例 #5
0
ファイル: ForceDirected.cs プロジェクト: zoebear/Radia
 public void EachEdge(EdgeAction del)
 {
     foreach (Edge e in graph.edges)
     {
         del(e, GetSpring(e));
     }
 }
コード例 #6
0
 public Edge(GraphNode one, GraphNode two, EdgeAction action, float cost, Vector3 position)
 {
     m_position      = position;
     m_NodeOne       = one;
     m_NodeTwo       = two;
     m_edgeAction    = action;
     m_traversalCost = cost;
 }
コード例 #7
0
ファイル: Edge.cs プロジェクト: codyn-net/studio
            public Node(EdgeAction action)
            {
                d_action = action;

                if (d_action != null)
                {
                    d_action.AddNotification("target", OnActionChanged);
                    d_action.AddNotification("equation", OnActionChanged);
                }
            }
コード例 #8
0
        /// <inheritdoc />
        public bool HideEdge(TEdge edge, string tag)
        {
            HiddenCollection collection = GetHiddenCollection(tag);
            var hideEdgeHandler         = new EdgeAction <TVertex, TEdge>(e => collection.HiddenEdges.Add(e));

            EdgeHidden += hideEdgeHandler;
            bool hidden = HideEdge(edge);

            EdgeHidden -= hideEdgeHandler;
            return(hidden);
        }
コード例 #9
0
ファイル: GraphHideHelper.cs プロジェクト: heder/GraphSharp
        public bool HideEdge(TEdge e, string tag)
        {
            var h   = GetHiddenCollection(tag);
            var eeh = new EdgeAction <TVertex, TEdge>(edge => h.hiddenEdges.Add(edge));

            EdgeHidden += eeh;
            bool ret = HideEdge(e);

            EdgeHidden -= eeh;
            return(ret);
        }
コード例 #10
0
 public SpriteBase()
 {
     txtre    = null;
     pstn     = new Rectangle(0, 0, 0, 0);
     cllsn    = new Rectangle(0, 0, 0, 0);
     tnt      = Color.White;
     fx       = SpriteEffects.None;
     eg       = EdgeAction.Stop;
     lstfrme  = 20;
     msprfrme = 20;
     tnt      = Color.White;
     spd      = new Vector2(0, 0);
     alive    = true;
 }
コード例 #11
0
ファイル: GraphHideHelper.cs プロジェクト: heder/GraphSharp
        public bool HideVertex(TVertex v, string tag)
        {
            HiddenCollection h = GetHiddenCollection(tag);
            var eeh            = new EdgeAction <TVertex, TEdge>(e => h.hiddenEdges.Add(e));
            var veh            = new VertexAction <TVertex>(vertex => h.hiddenVertices.Add(vertex));

            EdgeHidden   += eeh;
            VertexHidden += veh;
            bool ret = HideVertex(v);

            EdgeHidden   -= eeh;
            VertexHidden -= veh;
            return(ret);
        }
コード例 #12
0
        /// <inheritdoc />
        public bool HideVertex(TVertex vertex, string tag)
        {
            HiddenCollection collection = GetHiddenCollection(tag);
            var hideEdgeHandler         = new EdgeAction <TVertex, TEdge>(e => collection.HiddenEdges.Add(e));
            var hideVertexHandler       = new VertexAction <TVertex>(v => collection.HiddenVertices.Add(v));

            EdgeHidden   += hideEdgeHandler;
            VertexHidden += hideVertexHandler;

            bool hidden = HideVertex(vertex);

            EdgeHidden   -= hideEdgeHandler;
            VertexHidden -= hideVertexHandler;

            return(hidden);
        }
コード例 #13
0
        public SpriteBase(Texture2D txtre, Rectangle pstn, Vector2 spd, double msprfrme, Color tnt, SpriteEffects fx)
        {
            this.txtre    = txtre;
            this.pstn     = pstn;
            this.spd      = spd;
            this.msprfrme = msprfrme;
            //this.crntfrme = crntfrme;
            this.tnt = tnt;
            this.fx  = fx;
            this.eg  = EdgeAction.Stop;

            src = new Rectangle(0, 0, txtre.Width, txtre.Height);

            cllsn        = new Rectangle(0, 0, 0, 0);
            cllsn.X      = pstn.X;
            cllsn.Y      = pstn.Y;
            cllsn.Width  = pstn.Width;
            cllsn.Height = pstn.Height;

            this.alive = true;
        }
コード例 #14
0
        private bool HasCycles(IVertexListGraph <IBuilder, EquatableEdge <IBuilder> > graph)
        {
            var     dfs   = new DepthFirstSearchAlgorithm <IBuilder, EquatableEdge <IBuilder> >(graph);
            Boolean isDag = true;
            EdgeAction <IBuilder, EquatableEdge <IBuilder> > onBackEdge = edge =>
            {
                isDag = false;
                log.DebugFormat("Back edge: {0} -> {1}", edge.Source, edge.Target);
            };

            try
            {
                dfs.BackEdge += onBackEdge;
                dfs.Compute();
            }
            finally
            {
                dfs.BackEdge -= onBackEdge;
            }

            return(!isDag);
        }
コード例 #15
0
        protected void PrepareForSugiyama()
        {
            MinimizeHierarchicalEdgeLong();

            #region 1) Unhide general edges between vertices participating in the hierarchy
            var analyze = new HashSet <SugiVertex>();
            EdgeAction <SugiVertex, SugiEdge> eeh =
                edge =>
            {
                analyze.Add(edge.Source);
                analyze.Add(edge.Target);
            };
            _graph.EdgeUnhidden += eeh;
            _graph.UnhideEdgesIf(e => e.Type == EdgeTypes.General && _graph.ContainsVertex(e.Source) && _graph.ContainsVertex(e.Target));
            _graph.EdgeUnhidden -= eeh;
            #endregion

            #region 2) Move the vertices with general edges if possible
            foreach (var v in analyze)
            {
                //csak lejjebb lehet rakni
                //csak akkor, ha nincs hierarchikus kimeno el lefele
                //a legkozelebbi lehetseges szintre
                if (_graph.OutHierarchicalEdgeCount(v) == 0)
                {
                    //az altalanos elek kozul az alattalevok kozul a legkozelebbibre kell rakni
                    int newLayerIndex = _layers.Count;
                    foreach (var e in _graph.InGeneralEdges(v))
                    {
                        //nem erdemes tovabb folytatni, lejebb nem kerulhet
                        if (newLayerIndex == v.LayerIndex)
                        {
                            break;
                        }
                        if (e.Source.LayerIndex >= v.LayerIndex && e.Source.LayerIndex < newLayerIndex)
                        {
                            newLayerIndex = e.Source.LayerIndex;
                        }
                    }
                    foreach (var e in _graph.OutGeneralEdges(v))
                    {
                        //nem erdemes tovabb folytatni, lejebb nem kerulhet
                        if (newLayerIndex == v.LayerIndex)
                        {
                            break;
                        }
                        if (e.Target.LayerIndex >= v.LayerIndex && e.Target.LayerIndex < newLayerIndex)
                        {
                            newLayerIndex = e.Target.LayerIndex;
                        }
                    }
                    if (newLayerIndex < _layers.Count)
                    {
                        _layers[v.LayerIndex].Remove(v);
                        _layers[newLayerIndex].Add(v);
                    }
                }
            }
            #endregion

            // 3) Hide the general edges between different layers
            _graph.HideEdgesIf(e => (e.Type == EdgeTypes.General && e.Source.LayerIndex != e.Target.LayerIndex), GeneralEdgesBetweenDifferentLayersTag);

            //replace long edges with more segments and dummy vertices
            ReplaceLongEdges();

            ConstrainWidth();

            CopyPositions();
            OnIterationEnded("Preparation of the positions done.");
        }
コード例 #16
0
 internal void Update(EdgeAction edgeAction)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public MovingSprite()
     : base()
 {
     spd  = new Vector2(0, 0);
     edge = EdgeAction.Stop;
 }
コード例 #18
0
        private void PromoteEdgeSlices()
        {
            // This function splits all the edge actions on variables based
            // on the slice on which the operate on the target variable.
            var cp = d_actionedVariables;

            d_actionedVariables = new Dictionary <Variable, EdgeAction[]>();

            foreach (var pair in cp)
            {
                var variable = pair.Key;
                var actions  = pair.Value;

                var split = SplitActionsPerSlice(actions);

                if (split.Count == 1)
                {
                    // That's ok, no diversity means we can just use the
                    // normal code path
                    d_actionedVariables[pair.Key] = pair.Value;
                    continue;
                }

                // Contains a set of instructions for each value in the matrix
                // representing the final, new equation. Each value in the matrix
                // is a set of instructions because it can be a sum
                List <Cdn.Instruction>[] instructions = new List <Instruction> [variable.Dimension.Size()];

                // Ai! Cool stuff needs to happen here. Split out new
                // variables for these equations and setup a new edge action
                // representing the fully combined set. Complex you say? Indeed!
                foreach (var elem in split)
                {
                    // Combine elements with the same indices by simply doing a sum
                    var            eqs = Array.ConvertAll <Cdn.EdgeAction, Cdn.Expression>(elem.ToArray(), a => a.Equation);
                    Cdn.Expression sum = Cdn.Expression.Sum(eqs);

                    // Now make a variable for it
                    var nv = new Cdn.Variable(UniqueVariableName(variable.Object, String.Format("__d{0}", variable.Name)), sum, VariableFlags.None);
                    variable.Object.AddVariable(nv);

                    // Add relevant instructions as per slice
                    var slice = elem[0].Indices;

                    if (slice == null || slice.Length == 0)
                    {
                        // Empty slice is just the full range
                        slice = new int[variable.Dimension.Size()];

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

                    for (int i = 0; i < slice.Length; ++i)
                    {
                        if (instructions[slice[i]] == null)
                        {
                            instructions[slice[i]] = new List <Instruction>();
                        }

                        var vinstr = new Cdn.InstructionVariable(nv);

                        vinstr.SetSlice(new int[] { i }, new Cdn.Dimension {
                            Rows = 1, Columns = 1
                        });
                        instructions[slice[i]].Add(vinstr);
                    }
                }

                List <Cdn.Instruction> ret = new List <Instruction>();

                // Create substitute edge action
                foreach (var i in instructions)
                {
                    if (i == null)
                    {
                        ret.Add(new Cdn.InstructionNumber("0"));
                    }
                    else
                    {
                        // Add indexing instructions
                        ret.AddRange(i);

                        // Then add simple plus operators
                        for (int j = 0; j < i.Count - 1; ++j)
                        {
                            ret.Add(new Cdn.InstructionFunction((uint)Cdn.MathFunctionType.Plus, null, 2));
                        }
                    }
                }

                var minstr = new Cdn.InstructionMatrix(new Cdn.StackArgs(instructions.Length), variable.Dimension);
                ret.Add(minstr);

                var retex = new Cdn.Expression("");
                retex.SetInstructionsTake(ret.ToArray());

                var action = new Cdn.EdgeAction(variable.Name, retex);
                ((Cdn.Node)variable.Object).SelfEdge.AddAction(action);

                d_actionedVariables[variable] = new EdgeAction[] { action };
            }
        }
コード例 #19
0
ファイル: SimPathStore.cs プロジェクト: drzo/opensim4opencog
 private static Bitmap EdgeDetection(Bitmap Image, double Threshold, EdgeAction EdgeColor)
 {
     System.Drawing.Bitmap TempBitmap = Image;
     System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
     System.Drawing.Graphics NewGraphics = Graphics.FromImage(NewBitmap);
     NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), GraphicsUnit.Pixel);
     NewGraphics.Dispose();
     for (int x = 0; x < NewBitmap.Width; ++x)
     {
         for (int y = 0; y < NewBitmap.Height; ++y)
         {
             bool EdgeSet = false;
             Color CurrentColor = NewBitmap.GetPixel(x, y);
             if (y < NewBitmap.Height - 1 && x < NewBitmap.Width - 1)
             {
                 Color TempColor = NewBitmap.GetPixel(x + 1, y + 1);
                 if (Math.Sqrt(((CurrentColor.R - TempColor.R) * (CurrentColor.R - TempColor.R)) +
                     ((CurrentColor.G - TempColor.G) * (CurrentColor.G - TempColor.G)) +
                     ((CurrentColor.B - TempColor.B) * (CurrentColor.B - TempColor.B))) > Threshold)
                 {
                     EdgeColor(x, y);
                 }
                 EdgeSet = true;
             }
             if (y < NewBitmap.Height - 1 && !EdgeSet)
             {
                 Color TempColor = NewBitmap.GetPixel(x, y + 1);
                 if (Math.Sqrt(((CurrentColor.R - TempColor.R) * (CurrentColor.R - TempColor.R)) +
                     ((CurrentColor.G - TempColor.G) * (CurrentColor.G - TempColor.G)) +
                     ((CurrentColor.B - TempColor.B) * (CurrentColor.B - TempColor.B))) > Threshold)
                 {
                     EdgeColor(x, y);
                     // NewBitmap.SetPixel(x, y, EdgeColor);
                 }
                 EdgeSet = true;
             }
             if (x < NewBitmap.Width - 1 && !EdgeSet)
             {
                 Color TempColor = NewBitmap.GetPixel(x + 1, y);
                 if (Math.Sqrt(((CurrentColor.R - TempColor.R) * (CurrentColor.R - TempColor.R)) +
                     ((CurrentColor.G - TempColor.G) * (CurrentColor.G - TempColor.G)) +
                     ((CurrentColor.B - TempColor.B) * (CurrentColor.B - TempColor.B))) > Threshold)
                 {
                     EdgeColor(x, y);
                     //NewBitmap.SetPixel(x, y, EdgeColor);
                 }
                 EdgeSet = true;
             }
         }
     }
     return NewBitmap;
 }