Ejemplo n.º 1
0
        public void Paint(GraphicsLayer.IGraphics g, int width, int height)
        {
            Choosability.Graph graph = null;

            lock (_ModifyListsToken)
            {
                if (ParametersDirty)
                {
                    graph = new Choosability.Graph(GetEdgeWeights());
                    var n = Vertices.Count;

                    for (int i = 0; i < Vertices.Count; i++)
                    {
                        Vertices[i].IsUniversal = graph.Degree(i) == n - 1;
                    }

                    ParametersDirty = false;
                }

                foreach (var v in _vertices)
                {
                    v.Paint(g, width, height);
                }
                foreach (var e in _edges)
                {
                    e.Paint(g, width, height);
                }
            }

            if (graph != null)
            {
                DoGraphChange(graph);
            }
        }
Ejemplo n.º 2
0
        public Graph(Choosability.Graph g, List <Vector> position, bool directed = true)
            : this()
        {
            if (g.VertexWeight != null && g.VertexWeight.Count == g.N)
            {
                _vertices = g.Vertices.Select(v => new Vertex(position[v].X, position[v].Y, g.VertexWeight[v].ToString())).ToList();
            }
            else
            {
                _vertices = g.Vertices.Select(v => new Vertex(position[v].X, position[v].Y)).ToList();
            }
            _edges = new List <Edge>();

            for (int i = 0; i < g.N; i++)
            {
                for (int j = i + 1; j < g.N; j++)
                {
                    if (directed)
                    {
                        if (g.Directed[i, j])
                        {
                            _edges.Add(new Edge(_vertices[i], _vertices[j], Edge.Orientations.Forward));
                        }
                        else if (g.Adjacent[i, j])
                        {
                            _edges.Add(new Edge(_vertices[j], _vertices[i], Edge.Orientations.Forward));
                        }
                    }
                    else if (g.Adjacent[i, j])
                    {
                        _edges.Add(new Edge(_vertices[i], _vertices[j], Edge.Orientations.None));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static IEnumerable <Choosability.Graph> EnumerateWeightings(Choosability.Graph g)
        {
            if (g.MaxDegree > Delta)
            {
                yield break;
            }

            _wonWeightings = new List <List <int> >();
            foreach (var weighting in g.Vertices.Select(v => Enumerable.Range(g.Degree(v), Delta + 1 - g.Degree(v)).Reverse()).CartesianProduct())
            {
                var www = weighting.ToList();
                if (_wonWeightings.Any(ww => ww.Zip(www, (a, b) => a - b).Min() >= 0))
                {
                    continue;
                }

                var gg = g.Clone();
                gg.VertexWeight = www;

                if (LowGirth)
                {
                    if (!gg.Contains(BadG, true, GraphEnumerator.WeightConditionEqual))
                    {
                        continue;
                    }
                }

                yield return(gg);
            }
        }
Ejemplo n.º 4
0
        static bool Filter(Choosability.Graph g)
        {
            if (TriangleFree)
            {
                return(g.Vertices.All(v => g.IsIndependent(g.Neighbors[v])));
            }

            return(true);
        }
Ejemplo n.º 5
0
        static bool Filter(Choosability.Graph g)
        {
            if (g.MaxDegree > MaxDegree)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
 static IEnumerable <Choosability.Graph> EnumerateWeightings(Choosability.Graph g)
 {
     foreach (var weighting in g.Vertices.Select(v => Enumerable.Range(g.Degree(v), 2 + 1)).CartesianProduct())
     {
         var gg = g.Clone();
         gg.VertexWeight = weighting.ToList();
         yield return(gg);
     }
 }
Ejemplo n.º 7
0
        public void DoOutDegreePlusOneLabeling()
        {
            var g = new Choosability.Graph(_graph.GetEdgeWeights());

            for (int i = 0; i < _graph.Vertices.Count; i++)
            {
                _graph.Vertices[i].Label = (g.OutDegree(i) + 1).ToString();
            }

            Invalidate();
            GraphChanged();
        }
Ejemplo n.º 8
0
        public void DoIndexLabeling()
        {
            var g = new Choosability.Graph(_graph.GetEdgeWeights());

            for (int i = 0; i < _graph.Vertices.Count; i++)
            {
                _graph.Vertices[i].Label = i.ToString();
            }

            Invalidate();
            GraphChanged();
        }
Ejemplo n.º 9
0
        public GraphPolynomial(Choosability.Graph g)
        {
            _g = g;

            _priorNeighbors = new List <List <int> >();
            for (int w = 0; w < _g.N; w++)
            {
                _priorNeighbors.Add(new List <int>());
                for (int v = 0; v < w; v++)
                {
                    if (g[v, w])
                    {
                        _priorNeighbors[w].Add(v);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        static int MinEdgeDegree(Choosability.Graph g)
        {
            var min = int.MaxValue;

            for (int v = 0; v < g.N; v++)
            {
                for (int w = v + 1; w < g.N; w++)
                {
                    if (g[v, w])
                    {
                        var cc = ListUtility.Union(g.Neighbors[v], g.Neighbors[w]).Count;
                        min = Math.Min(min, cc);
                    }
                }
            }

            return(min);
        }
Ejemplo n.º 11
0
 static bool PotentialAtMost(Choosability.Graph g, int bound)
 {
     return(P(g, K) <= bound);
 }
Ejemplo n.º 12
0
 static int P(Choosability.Graph g, int k)
 {
     return((k - 2) * (k + 1) * g.N - 2 * (k - 1) * g.E);
 }
Ejemplo n.º 13
0
 static IEnumerable <Choosability.Graph> Secondary(Choosability.Graph g)
 {
     yield return(g);
 }
Ejemplo n.º 14
0
 void DoGraphChange(Choosability.Graph graph)
 {
 }
Ejemplo n.º 15
0
        public static void DrawGraph(Choosability.Graph g, string path, bool labelEdges = false)
        {
            var renderer = new DotRenderer(@"C:\Program Files (x86)\Graphviz2.38\bin\dot.exe");

            renderer.Render(g.ToDotWithFactors(labelEdges), path, DotRenderType.png);
        }
Ejemplo n.º 16
0
        public static int GetCoefficient(this Choosability.Graph g, int[] power)
        {
            var gp = new GraphPolynomial(g);

            return(gp.GetCoefficient(power));
        }
Ejemplo n.º 17
0
        public static int GetSignSum(this Choosability.Graph g, int[] power)
        {
            var gp = new GraphPolynomial(g);

            return(gp.GetSignSum(power));
        }