Beispiel #1
0
 private void finishWork()
 {
     working.push();
     time      = 0;
     isWorking = false;
     working   = idle;
 }
Beispiel #2
0
 static Stack <step> makeOrder(step root, List <step> order)
 {
     foreach (step s in root.getPred())
     {
         if (!s.getPushed())
         {
             order.Add(s);
             s.push();
             Console.Write(s.getC());
             Console.WriteLine(" added");
         }
     }
     if (order.Count != 0)
     {
         order.Sort(compareSteps);
         step top = order[0];
         Console.Write(top.getC());
         Console.WriteLine(" pushed");
         order.Remove(top);
         Stack <step> orderStack = makeOrder(top, order);
         orderStack.Push(top);
         return(orderStack);
     }
     return(new Stack <step>());
 }
Beispiel #3
0
 static step[] addAllSteps(List <char> allStepChars)
 {
     step[] steps = new step[allStepChars.Count];
     for (int i = 0; i < steps.Length; i++)
     {
         steps[i] = new step(allStepChars[i]);
     }
     return(steps);
 }
Beispiel #4
0
 static void printSucc(step inStep)
 {
     foreach (step s in inStep.getSucc())
     {
         Console.Write(s.getC());
     }
     foreach (step s in inStep.getSucc())
     {
         printSucc(s);
     }
 }
Beispiel #5
0
        static void printOrder(step root)
        {
            List <step> order = new List <step>();

            root.push();
            Stack <step> orderStack = makeOrder(root, order);

            while (orderStack.Count != 0)
            {
                Console.Write(orderStack.Pop().getC());
            }
            Console.Write(root.getC());
        }
Beispiel #6
0
 static void printPred(step root)
 {
     Console.Write(root.getC());
     Console.Write(": ");
     foreach (step s in root.getPred())
     {
         Console.Write(s.getC());
     }
     Console.WriteLine();
     foreach (step s in root.getPred())
     {
         printPred(s);
     }
 }
Beispiel #7
0
        static void Main()
        {
            //ta in indata som array av par [a,b] ==> a krävs för b
            char[,] input = getInput();
            //spara varje steg som en char med referenser fram och bak.
            //lägg in de i random ordning
            //en referens start
            //sista blir null
            //sortera enligt input glöm inte att de ska vara i alfabetsordning!
            step[] steps = makeArr(input);
            step   root  = makeTree(input, steps);

            //!!!!! det chillar en sekund även fast det finns jobbb, fix
            //Stack<step> order = printOrderNew(root,steps);  -- uppgiftA
            Console.WriteLine("S \t W1 \t W2 \t W3 \t W4 \t W5 \t Done");
            int counter = 0;

            worker[] wArr = new worker[5]; //5
            for (int i = 0; i < wArr.Length; i++)
            {
                wArr[i] = new worker();
            }
            while (notDone(steps))
            {
                foreach (worker w in wArr)
                {
                    if (w.haveWork())
                    {
                        w.work();
                    }
                    if (!w.haveWork())
                    {
                        if (isReadyStep(steps))
                        {
                            w.setStep(findReadyStep(steps));
                        }
                    }
                }
                Console.Write(counter + "\t" + wArr[0].getWork().getC() + "\t" + wArr[1].getWork().getC() + "\t" + wArr[2].getWork().getC() + "\t" + wArr[3].getWork().getC() + "\t" + wArr[4].getWork().getC() + "\t");
                foreach (step s in steps)
                {
                    if (s.getPushed())
                    {
                        Console.Write(s.getC());
                    }
                }
                Console.WriteLine();
                counter++;
            }
        }
Beispiel #8
0
        static step[] sortArr(step[] steps)
        {
            int lowest;

            for (int i = 0; i < steps.Length; i++)
            {
                lowest = findLowestIndex(steps, i);
                if (steps[i].getC() > steps[lowest].getC())
                {
                    step temp = steps[i];
                    steps[i]      = steps[lowest];
                    steps[lowest] = temp;
                }
            }
            return(steps);
        }
Beispiel #9
0
        static Stack <step> printOrderNew(step root, step[] steps)
        {
            steps = sortArr(steps);
            Stack <step> order    = new Stack <step>();
            Stack <step> orderRev = new Stack <step>();

            order.Push(root);
            root.push();

            while (notEmpty(steps))
            {
                step temp = getNext(steps);
                order.Push(temp);
                temp.push();
            }
            while (order.Count != 0)
            {
                orderRev.Push(order.Pop());
            }
            return(orderRev);
        }
Beispiel #10
0
 public void addPred(step predIn)
 {
     pred.Add(predIn);
 }
Beispiel #11
0
 public void addSucc(step succIn)
 {
     succ.Add(succIn);
 }
Beispiel #12
0
        static step makeTree(char [,] input, step[] allSteps)
        {
            step root = sortSteps(allSteps, input);

            return(root);
        }
Beispiel #13
0
 private static int compareSteps(step left, step right)
 {
     return(left.getC().CompareTo(right.getC()));
 }
Beispiel #14
0
 public void setStep(step inStep)
 {
     working   = inStep;
     isWorking = true;
     working.setWorked();
 }