Exemple #1
0
    void calculateLatest(ref List <CPMEvent> EventList)
    {
        for (int i = EventList.Count - 1; i >= 0; i--)
        {
            CPMEvent ev = EventList[i];

            foreach (CPMAction ac in ev.In)
            {
                if (ev.latest - ac.duration < EventList[ac.from - 1].latest)
                {
                    EventList[ac.from - 1].latest = ev.latest - ac.duration;
                }
            }
        }
    }
Exemple #2
0
    void calculateDeepness(ref CPMEvent ev)
    {
        if (ev.Out.Count != 0)
        {
            foreach (var action in ev.Out)
            {
                if (ev.deepness + 1 < eventsGlobal[action.to - 1].deepness)
                {
                    eventsGlobal[action.to - 1].deepness = ev.deepness + 1;
                }

                CPMEvent nextEvent = eventsGlobal[action.to - 1];
                calculateDeepness(ref nextEvent);
            }
        }
    }
Exemple #3
0
    void chooseCPM(List <CPMEvent> EventList, CPMEvent current, ref List <CPMEvent> CriticalPathEvents, ref List <CPMAction> CriticalPathActions)
    {
        if (current.In.Count != 0)
        {
            CPMEvent next;
            foreach (CPMAction action in current.In)
            {
                if (current.latest - action.duration == EventList[action.from - 1].earliest)
                {
                    next = EventList[action.from - 1];

                    CriticalPathEvents.Insert(0, EventList[action.from - 1]);
                    CriticalPathActions.Insert(0, action);

                    chooseCPM(EventList, next, ref CriticalPathEvents, ref CriticalPathActions);
                    break;
                }
            }
        }
    }
Exemple #4
0
    public void CalculateCPM()
    {
        List <CPMAction> Actions;

        if (predefinedConfigToggle.isOn)
        {
            Actions = new List <CPMAction> {
                new CPMAction('A', 3, 1, 2),
                new CPMAction('B', 4, 2, 3),
                new CPMAction('C', 6, 2, 4),
                new CPMAction('D', 7, 3, 5),
                new CPMAction('E', 1, 5, 7),
                new CPMAction('F', 2, 4, 7),
                new CPMAction('G', 3, 4, 6),
                new CPMAction('H', 4, 6, 7),
                new CPMAction('I', 1, 7, 8),
                new CPMAction('J', 2, 8, 9)
            };
        }
        else
        {
            Actions = ReadActionsInfoFromInputFields();
        }

        foreach (var item in Actions)
        {
            item.Print();
        }

        List <CPMEvent> Events = createEvents(Actions);

        assignActionsToEvents(Actions, ref Events);

        calculateEarliest(ref Events);
        Events[Events.Count - 1].latest = Events[Events.Count - 1].earliest;
        calculateLatest(ref Events);

        foreach (var item in Events)
        {
            item.Print();
        }

        List <CPMEvent> CriticalPathEvents = new List <CPMEvent> {
            Events[Events.Count - 1]
        };
        List <CPMAction> CriticalPathActions = new List <CPMAction>();

        chooseCPM(Events, Events[Events.Count - 1], ref CriticalPathEvents, ref CriticalPathActions);

        string cpe = "";

        foreach (CPMEvent ev in CriticalPathEvents)
        {
            cpe += ev.eventID + " ";
        }
        CriticalActionPathText.text = cpe;

        string cpa = "";

        foreach (CPMAction ac in CriticalPathActions)
        {
            cpa += ac.actionID + " ";
        }
        CriticalEventPathText.text = cpa;

        CriticalTimeText.text = calculateCPMTime(CriticalPathActions).ToString();

        actionsGlobal = Actions;
        eventsGlobal  = Events;

        CPMEvent firstEvent = Events[0];

        firstEvent.deepness = 0;
        calculateDeepness(ref firstEvent);

        foreach (CPMEvent ev in Events)
        {
            print(ev.deepness);
        }

        CirclesManager.drawCircles();
        LineManager.drawLines(CriticalPathActions);

        CirclesManager.ColorCriticalPath(CriticalPathEvents);
    }