/* * task.h - TaskJuggler * * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 * Chris Schlaeger * SPDX-FileCopyrightText: 2011 Dag Andersen * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * $Id$ */ #ifndef _Task_h_ #define _Task_h_ #include "plantj_export.h" // #include #include #include #include "debug.h" #include "TaskList.h" #include "TaskScenario.h" #include "ShiftSelectionList.h" #include "LoopDetectorInfo.h" #include "TaskDependency.h" // #include "Journal.h" class QDomElement; class QDomDocument; namespace TJ { class Project; class Resource; // class Account; class Shift; class ShiftSelection; class TaskList; class Allocation; class Interval; /** * This class stores all task related information and provides methods to * manipulate them. It provides fundamental functions like the scheduler. * * @short The class that holds all task related information. * @see Resource * @see CoreAttributes * @author Chris Schlaeger */ class PLANTJ_EXPORT Task : public CoreAttributes { friend int TaskList::compareItemsLevel(CoreAttributes*, CoreAttributes*, int); public: Task(Project* prj, const QString& id_, const QString& n, Task* p, const QString& f, int l); ~Task() override; CAType getType() const override { return CA_Task; } Task* getParent() const { return static_cast(parent); } TaskListIterator getSubListIterator() const { return TaskListIterator(*sub); } enum SchedulingInfo { ASAP, ALAP }; void inheritValues(); void setProjectId(const QString& i) { projectId = i; } const QString& getProjectId() const { return projectId; } void setNote(const QString& d) { note = d; } const QString& getNote() const { return note; } // void addJournalEntry(JournalEntry* entry); // bool hasJournal() const { return !journal.isEmpty(); } // Journal::Iterator getJournalIterator() const; void setReference(const QString& r, const QString& l) { ref = r; refLabel = l; } const QString& getReference() const { return ref; } const QString& getReferenceLabel() const { return refLabel; } void setScheduling(SchedulingInfo si) { scheduling = si; } SchedulingInfo getScheduling() const { return scheduling; } void setPriority(int p) { priority = p; } int getPriority() const { return priority; } void setResponsible(Resource* r) { responsible = r; } Resource* getResponsible() const { return responsible; } void setMilestone(bool ms = true) { milestone = ms; } bool isMilestone() const { return milestone; } // // // void setAccount(Account* a) { account = a; } // // // Account* getAccount() const { return account; } TaskDependency* addDepends(const QString& id); QList getDepends() const { return depends; } QListIterator getDependsIterator() const { return QListIterator(depends); } TaskDependency* addPrecedes(const QString& id); QList getPrecedes() const { return precedes; } QListIterator getPrecedesIterator() const { return QListIterator(precedes); } /// Add working time defined in @p shift for interval @p i bool addShift(const Interval& i, Shift* s); /// Return true if @p slot is defined as working time /// Falls back to project definitions if no shifts has been defined for this task bool isWorkingTime(const Interval &slot) const; void addAllocation(Allocation* a) { allocations.append(a); } void purgeAllocations() { allocations.clear(); } QListIterator getAllocationIterator() const { return QListIterator(allocations); } TaskListIterator getPreviousIterator() const { return TaskListIterator(previous); } bool hasPrevious() const { return !previous.isEmpty(); } TaskListIterator getFollowersIterator() const { return TaskListIterator(followers); } bool hasFollowers() const { return !followers.isEmpty(); } bool hasPrevious(const Task* t) { return previous.indexOf(const_cast(t)) != -1; } bool hasFollower(const Task* t) { return followers.indexOf(const_cast(t)) != -1; } // The following group of functions operates only on scenario variables. void setSpecifiedStart(int sc, time_t s) { scenarios[sc].specifiedStart = s; //qDebug()<<"Task::setSpecifiedStart:"<(t)); } /** * @retval true if itself or one of its subtasks (recursively) is on the critical path * @retval false otherwise. */ bool isOrHasDescendantOnCriticalPath(int sc) const; bool isContainer() const { return !sub->isEmpty(); } bool xRef(QMap& hash); void implicitXRef(); void sortAllocations(); void saveSpecifiedBookedResources(); QString resolveId(QString relId); bool preScheduleOk(int sc); bool scheduleOk(int sc) const; /** * Checks for loops in task interdependencies starting with the current * task. * @param chkedTaskList The list of already checked tasks. Will be appended * to. * @retval true if a loop was detected. * @retval false otherwise. */ bool loopDetector(LDIList& chkedTaskList) const; bool checkDetermination(int sc) const; void computeBuffers(); time_t nextSlot(time_t slotDuration) const; bool isReadyForScheduling() const; bool schedule(int sc, time_t& reqStart, time_t duration); void propagateInitialValues(int sc); void setRunaway(); bool isRunaway() const; bool isSubTask(const Task* t) const; bool isSchedulingDone() const { return schedulingDone; } void errorMessage(const QString& msg) const; void warningMessage(const QString& msg) const; QDomElement xmlElement(QDomDocument& doc, bool absId = true); TaskList getSuccessors() const { return successors; } TaskList getPredecessors() const { return predecessors; } bool hasAlapPredecessor() const; private: friend class Project; void propagateStart(int sc, time_t date); void propagateEnd(int sc, time_t date); /** * Checks for loops in task interdependencies starting with the current * task under ASAP or ALAP scheduling. * @param ckedTaskList The list of already checked tasks. Will be appended * to. * @retval true if a loop was detected. * @retval false otherwise. */ bool loopDetection(LDIList& list, LDIList& chkedTaskList, bool atEnd, bool fromOutside) const; bool checkPathForLoops(LDIList& list, bool atEnd) const; bool scheduleContainer(int sc); Task* subFirst() { return nullptr/*(Task*) sub->first()*/; } Task* subNext() { return nullptr/*(Task*) sub->next()*/; } /// Returns the availability of @p resource and its required resources (if any) int isAvailable(Allocation *allocation, Resource *resource, time_t slot) const; /// Book resource @p r if it (and its required resources) is available bool bookResource(Allocation *allocation, Resource* r, time_t day, time_t duration, int& slotsToLimit, int& availability); void bookResources(int sc, time_t day, time_t duration); void addBookedResource(Resource* r) { if (bookedResources.indexOf((CoreAttributes*) r) == -1) bookedResources.inSort((CoreAttributes*) r); } QList createCandidateList(int sc, time_t date, Allocation* a); time_t earliestStart(int sc) const; time_t latestEnd(int sc) const; bool startCanBeDetermined(LDIList& list, int sc) const; bool endCanBeDetermined(LDIList& list, int sc) const; bool hasStartDependency(int sc) const; bool hasEndDependency(int sc) const; bool hasStartDependency() const; bool hasEndDependency() const; bool analyzePath(int sc, double minSlack, time_t pathStart, long busyTime, long worstMinSlackTime, long& checked, long& found); void collectTransientFollowers(TaskList& list); bool countMilestones(int sc, time_t now, int& totalMilestones, int& completedMilestones, int& reportedCompletedMilestones); bool sumUpEffort(int sc, time_t now, double& totalEffort, double& completedEffort, double& reportedCompletedEffort); /// A longer description of the task. QString note; /// List of notes with a date attached. // Journal journal; /// A reference to an external document QString ref; /// A label used instead of the reference QString refLabel; /** * The dependencies of the task are stored twice. depends and precedes * store the information specified in the project file. For convenience we * also store the backward dependency together with the specified * dependencies in predecessors and successors. */ QList depends; /// @see depends QList precedes; /** * A list of tasks that must precede this task. */ TaskList predecessors; /** * A list of tasks that must follow this task. */ TaskList successors; /** * A list of all tasks that precede this task. It's the combination of * depends and predecessors. This is redundant information but stored for * convenience. Interdependent tasks are linked in a doubly linked list. */ TaskList previous; /** * A list of all tasks that follow this task. It's the combination of * precedes and successors. This is redundant information but stored for * convenience. Interdependent tasks are linked in a doubly linked list. */ TaskList followers; /** * The ID of the project this task belongs to. This is only * meaningful if multiple projects are joined to create a big * project. */ QString projectId; /// True if the task is a milestone. bool milestone; /** * The priority is used during scheduling. The higher the priority * the more likely the task will get the requested resources. */ int priority; /// The scheduling policy of the task. SchedulingInfo scheduling; /// ID of responsible resource. Resource* responsible; /// Tasks may only be worked on during the specified shifts. /// Also defines the working time of length tasks ShiftSelectionList shifts; /// List of resource allocations requested by the task QList allocations; /// Account where the credits of the task are credited to. // Account* account; TaskScenario* scenarios; /* The following group of variables store values generated during a * scheduler run. They might be initialized by other values and/or * they might contain results of the scheduling run. But they should * never be initialized directly or read out directly. They should have * corresponding scenario variables. The get/set interface functions * should only access the scenario variables. */ /// Day when the task should start time_t start; /// Day when the task should end time_t end; /// Length in working days double length; /// Effort (in man days) needed to complete the task double effort; /// Duration in calendar days double duration; /// The already completed effort in a scheduler run. double doneEffort; /// The already completed length in a scheduler run. double doneLength; /// The already completed duration in a scheduler run. double doneDuration; /** * Set to true when the first time slots have with resource usage * have been allocated. */ bool workStarted; /** * Since the full time slot might not be available we need to * store the tentative start of a task in a separate * variable. Storing the information in 'start' would mark the * task as fully scheduled which might not yet be the case. */ time_t tentativeStart; /** * Since the full time slot might not be available we need to * store the tentative end of a task in a separate * variable. Storing the information in 'end' would mark the task * as fully scheduled which might not yet be the case. */ time_t tentativeEnd; /** * Depending on the scheduling policy the tasks need to be scheduled * from one end the other in a continuous way. No timeslot may be * scheduled twice. This variable stores information about the last * allocation, so we can make sure the next slot is exactly adjacent * the previous one. */ time_t lastSlot; /// This variable is set to true when the task has been scheduled. bool schedulingDone; /** This flag is set when the task does not fit into the project time * frame. */ bool runAway; /// A list of all the resources booked for this task. ResourceList bookedResources; } ; } // namespace TJ PLANTJ_EXPORT QDebug operator<<(QDebug dbg, const TJ::Task* t); PLANTJ_EXPORT QDebug operator<<(QDebug dbg, const TJ::Task& t); #endif