Ejemplo n.º 1
0
        public void Delete(ref AdjList adjList, ref Stack stack)
        {
            deletedDegree = degree;
            stack.Push(this);

            adjList.TraverseOnDelete(course);
        }
Ejemplo n.º 2
0
        public void RandomPass(ref AdjList adjList, ref Stack stack)
        {
            int newColor = 0;

            while (adjList.IsAdjacentToColored(course, newColor))
            {
                ++newColor;
            }

            color = newColor;
            stack.Push(this);
        }
Ejemplo n.º 3
0
        public void WelshPowell(ref AdjList adjList, ref Stack stack)
        {
            Vertex curr;

            for (int i = maxDegree; i >= 0; i--)
            {
                curr = DL[i];
                while (curr != null)
                {
                    curr.WelshPowellPass(maxDegree, ref adjList, ref stack);
                    curr = curr.degNext;
                }
            }
        }
Ejemplo n.º 4
0
        public int GetMinColors(ref AdjList adjList, ref Stack stack)
        {
            Vertex curr;

            for (int i = 0; i <= maxDegree; i++)
            {
                curr = DL[i];
                while (curr != null)
                {
                    curr.Delete(ref adjList, ref stack);
                    curr = curr.degNext;
                }
            }

            return(stack.GetMaxDegreeDeleted() + 1);
        }
Ejemplo n.º 5
0
 public void WelshPowellPass(int numColors, ref AdjList adjList, ref Stack stack)
 {
     if (bannedColors == null)
     {
         bannedColors = new int[numColors];
     }
     for (int i = 0; i < numColors; i++)
     {
         if (bannedColors[i] == 0)
         {
             color = i;
             break;
         }
     }
     adjList.BanColor(course, color, numColors);
     stack.Push(this);
 }
Ejemplo n.º 6
0
 public int SmallestLastPass(int numColors, ref AdjList adjList)
 {
     if (bannedColors == null)
     {
         bannedColors = new int[numColors];
     }
     for (int i = 0; i < numColors; i++)
     {
         if (bannedColors[i] == 0)
         {
             color = i;
             break;
         }
     }
     adjList.BanColor(course, color, numColors);
     return(color);
 }
Ejemplo n.º 7
0
        public void BuildGraph()
        {
            StreamReader srP = new StreamReader(pathToP);
            StreamReader srE = new StreamReader(pathToE);

            //First line of P tells you the number of courses
            String pLine = srP.ReadLine();

            int.TryParse(pLine, out numCourses);
            //Allocate memory
            adjList   = new AdjList(numCourses + 1);
            degList   = new DegreeList(numCourses + 1);
            verticies = new Vertex[numCourses + 1];
            stack     = new Stack(numCourses + 1);

            pLine = srP.ReadLine();

            //First line of E is always 0 so skip it
            String eLine = srE.ReadLine();

            eLine = srE.ReadLine();

            int courseNumber = 1;
            int extra        = 0;
            int parsed;
            int curr;
            int prev;

            int.TryParse(pLine, out prev);

            while (pLine != null)
            {
                pLine = srP.ReadLine();
                while (pLine == "0")
                {
                    ++extra;
                    pLine = srP.ReadLine();
                }
                if (pLine == null)
                {
                    while (eLine != null)
                    {
                        int.TryParse(eLine, out parsed);

                        AddVertex(parsed, courseNumber);
                        eLine = srE.ReadLine();
                    }
                }
                else
                {
                    int.TryParse(pLine, out curr);
                    int difference = curr - prev;
                    for (int i = 0; i < difference; i++)
                    {
                        int.TryParse(eLine, out parsed);

                        AddVertex(parsed, courseNumber);
                        eLine = srE.ReadLine();
                    }
                    prev         = curr;
                    courseNumber = courseNumber + extra + 1;
                    extra        = 0;
                }
            }

            adjList.BuildDegreeList(ref verticies, ref degList);
            if (verbose)
            {
                adjList.Print();
                degList.Print();
            }
            graphBuilt = true;
        }