コード例 #1
0
ファイル: Form1.cs プロジェクト: NSoft-SteAleX/Graphs
 private void button22_Click(object sender, EventArgs e)
 {
     DrawFull(0);
     try
     {
         Task2Dialog td = new Task2Dialog();
         td.maxVertex = test.VertexCount;
         td.ShowDialog();
         if (!td.confirmed)
         {
             return;
         }
         TaskTwo tt = new TaskTwo();
         tt.Set(test, td.selectedval);
         tt.Solve();
         tt = new TaskTwo();
         for (int i = 0; i < test.VertexCount; i++)
         {
             Misc.Vertex <int> cv = test.GetVertex(i);
             if (cv.value == td.distance)
             {
                 en.GetControlbyName(i.ToString(), ctrls).BackgroundImage = iterator;
             }
         }
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.Message + "\nThis will not affect app work", "error during solution search", MessageBoxButtons.OK);
     }
 }
コード例 #2
0
        public List <Misc.Vertex <VertexType> > Vertexes = new List <Misc.Vertex <VertexType> >();// contains vertex objects

        public MatrixBasedGraph(int VertexCount, bool oriented)
        {
            this.VertexCount = VertexCount;
            IsDirected       = oriented;
            Data             = new Misc.Edge <EdgeType> [VertexCount, VertexCount];
            for (int i = 0; i < VertexCount; i++)
            {
                Misc.Vertex <VertexType> temp = new Misc.Vertex <VertexType>();
                temp.id = i;
                Vertexes.Add(temp);
            }
        }
コード例 #3
0
 public object Result()
 {
     bool [] vrts = new bool[g.VertexCount];
     for (int i = 0; i < g.VertexCount; i++)
     {
         Misc.Vertex <int> cv = g.GetVertex(i);
         if (cv._inner == Color.Black)
         {
             vrts[i] = true;
         }
     }
     return(vrts);
 }
コード例 #4
0
        public List <Misc.Vertex <VertexType> > vertexes = new List <Misc.Vertex <VertexType> >(); // contains vertex objects


        public ListBasedGraph(int VertexCount, bool oriented)
        {
            IsDirected       = oriented;
            this.VertexCount = VertexCount;
            data             = new List <List <Misc.Vertex <VertexType> > >(VertexCount);
            for (int i = 0; i < VertexCount; i++)
            {
                Misc.Vertex <VertexType> sample = new Misc.Vertex <VertexType>();
                sample.id = i;
                vertexes.Add(sample); //adding vertex to array(list)
                List <Misc.Vertex <VertexType> > temp = new List <Misc.Vertex <VertexType> >();
                data.Add(temp);       // creating 2nd level of list
            }
        }
コード例 #5
0
        Color ColorRoute(Misc.Vertex <int> curr, Color inpc) // inpc, income predicted color
        {
            Color newpc = Color.OrangeRed;                   // some mess to make compiler happy

            if (inpc == Color.White)
            {
                newpc = Color.Black;
            }
            else
            {
                newpc = Color.White;
            }
            List <Color> currlist = new List <Color>();
            Color        back;
            int          i = 0;

            if (curr._inner != Color.Gray)
            {
                return(curr._inner);
            }
            curr._inner = Color.Red;
            g.CreateIterator(curr.id);
            while (g.IsValid())
            {
                Misc.Vertex <int> newcurr;
                newcurr = g.GetVertex(g.Current());    // get linked vertex
                back    = ColorRoute(newcurr, newpc);
                if (back == Color.Red)
                {
                    newcurr._inner = newpc; back = newpc;
                }
                currlist.Add(back);
                g.CreateIterator(curr.id);
                for (int j = 0; j < i; j++)
                {
                    g.MoveNext();
                }
                g.MoveNext();
                i++;
            }

            if (currlist.Count > 0)
            {
                bool iswhite = (currlist[0] == Color.White);
                for (int j = 0; j < currlist.Count; j++)
                {
                    if (currlist[j] == Color.Red)
                    {
                        continue;
                    }
                    bool localcc = (currlist[j] == Color.White);
                    if (localcc != iswhite)
                    {
                        throw new Exception("Cant find solution");
                    }
                }
                if (iswhite)
                {
                    curr._inner = Color.Black;
                }
                else
                {
                    curr._inner = Color.White;
                }
            }
            else
            {
                curr._inner = inpc;
            }
            //  check bypassed, things are looking good, now able to color current vertex
            return(curr._inner);
        }