コード例 #1
0
ファイル: Crewman.cs プロジェクト: kouweizhong/SimManning
 /// <summary>
 /// Assign the crewman to a running task.
 /// This starts by calling <see cref="RefreshStatus"/>, and increase <see cref="CurrentLoad"/>.
 /// </summary>
 /// <param name="time">Current simulation time</param>
 /// <param name="phase">Current phase</param>
 /// <param name="task">New task</param>
 public virtual void AssignTask(SimulationTime time, Phase phase, SimulationTask task)
 {
     RefreshStatus(time);
     this.tasksAssigned.Add(task);
     if (task.IsWork)
     {
         currentLoad++;
     }
 }
コード例 #2
0
ファイル: Crewman.cs プロジェクト: kouweizhong/SimManning
 /// <summary>
 /// Remove a running or completed task from the crewman.
 /// This starts by calling <see cref="RefreshStatus"/>, and decrease <see cref="CurrentLoad"/>.
 /// </summary>
 /// <param name="time">Current simulation time</param>
 /// <param name="phase">Current phase</param>
 /// <param name="task">Task dismissed</param>
 public virtual void DismissTask(SimulationTime time, Phase phase, SimulationTask task)
 {
     RefreshStatus(time);
     this.tasksAssigned.Remove(task);
     if (task.IsWork)
     {
         this.currentLoad--;
         Debug.Assert(currentLoad >= 0, "Current load must be positive!");
         if (this.currentLoad < 0)
         {
             this.currentLoad = 0;
         }
     }
 }
コード例 #3
0
 public virtual bool Identical(SimulationTask task2)
 {
     if ((task2 == null) || (this.id != task2.id) || (this.name != task2.name) ||                //Do not compare description
         ((!((this.Duration.Unit == TimeUnit.Undefined) && (task2.Duration.Unit == TimeUnit.Undefined))) && (this.Duration != task2.Duration)) ||
         /*(this.systemTask != task2.systemTask) ||*/ (this.autoExpandToAllCrewmen != task2.autoExpandToAllCrewmen) ||
         (this.taskInterruptionPolicy != task2.taskInterruptionPolicy) || (this.phaseInterruptionPolicy != task2.phaseInterruptionPolicy) || (this.scenarioInterruptionPolicy != task2.scenarioInterruptionPolicy) ||
         (this.interruptionErrorPolicy != task2.interruptionErrorPolicy) ||
         (this.duplicatesPolicy != task2.duplicatesPolicy) || (this.Rotation != task2.Rotation) || (this.numberOfCrewmenNeeded != task2.numberOfCrewmenNeeded) ||
         (this.onHolidays != task2.onHolidays) || (this.priority != task2.priority) || (this.relativeDate != task2.relativeDate) ||
         (this.taskType != task2.taskType) || (this.relativeTime != task2.relativeTime) ||
         ((!((this.StartDate.Unit == TimeUnit.Undefined) && (task2.StartDate.Unit == TimeUnit.Undefined))) && (this.StartDate != task2.StartDate)) ||
         ((!((this.DateOffset.Unit == TimeUnit.Undefined) && (task2.DateOffset.Unit == TimeUnit.Undefined))) && (this.DateOffset != task2.DateOffset)) ||
         (this.DailyHourEnd != task2.DailyHourEnd) || (this.DailyHourStart != task2.DailyHourStart) ||
         (!this.phaseTypes.OrderBy(i => i).SequenceEqual(task2.phaseTypes.OrderBy(i => i))) || (!this.crewmanTypes.SequenceEqual(task2.crewmanTypes)) ||
         (this.parallelTasks.Count != task2.parallelTasks.Count) || (this.slaveTasks.Count != task2.slaveTasks.Count) || (this.masterTasks.Count != task2.masterTasks.Count))
     {
         return(false);
     }
     foreach (var otherTaskId in this.parallelTasks.Values.Select(t => t.id))
     {
         if (!task2.parallelTasks.ContainsKey(otherTaskId))
         {
             return(false);
         }
     }
     foreach (var otherTaskId in this.slaveTasks.Values.Select(t => t.id))
     {
         if (!task2.slaveTasks.ContainsKey(otherTaskId))
         {
             return(false);
         }
     }
     foreach (var otherTaskId in this.masterTasks.Values.Select(t => t.id))
     {
         if (!task2.masterTasks.ContainsKey(otherTaskId))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #4
0
        /// <summary>
        /// Create a new task based on a reference task from which the different parameters will be copied.
        /// </summary>
        /// <param name="id">The ID of the new task, potentially different from the reference task.</param>
        /// <param name="refTask">The parent task from which parameters will be copied</param>
        /// <param name="linkingType">Controls the possible sharing with the reference task some data structure</param>
        protected SimulationTask(int id, SimulationTask refTask, TaskLinkingType linkingType)
        {
            this.id      = id;
            this.refTask = refTask;
            Reset();
            {            //Always linked
                this.crewmanTypes = refTask.crewmanTypes;
                this.phaseTypes   = refTask.phaseTypes;
            }
            switch (linkingType)
            {
            case TaskLinkingType.Linked:
                this.simulationCurrentQualifications = refTask.simulationCurrentQualifications;
                this.parallelTasks = refTask.parallelTasks;
                this.slaveTasks    = refTask.slaveTasks;
                this.masterTasks   = refTask.masterTasks;
                break;

            case TaskLinkingType.Copy:
                //this.crewmanTypes = refTask.crewmanTypes.ToList();
                //this.phaseTypes = refTask.phaseTypes.ToList();
                this.simulationCurrentQualifications = new Dictionary <Crewman, byte>(this.refTask.simulationCurrentQualifications);
                this.parallelTasks = new Dictionary <int, SimulationTask>(this.refTask.parallelTasks);
                this.slaveTasks    = new Dictionary <int, SimulationTask>(this.refTask.slaveTasks);
                this.masterTasks   = new Dictionary <int, SimulationTask>(this.refTask.masterTasks);
                break;

            case TaskLinkingType.Clear:
            default:
                //this.crewmanTypes = refTask.crewmanTypes.ToList();
                //this.phaseTypes = refTask.phaseTypes.ToList();
                this.simulationCurrentQualifications = new Dictionary <Crewman, byte>(this.refTask.simulationCurrentQualifications);
                this.parallelTasks = new Dictionary <int, SimulationTask>();
                this.slaveTasks    = new Dictionary <int, SimulationTask>();
                this.masterTasks   = new Dictionary <int, SimulationTask>();
                break;
            }
            this.refTask = refTask.RootTask;
        }
コード例 #5
0
 /// <summary>
 /// Create a new task based on a reference task from which the different parameters will be copied (including task ID).
 /// </summary>
 /// <param name="refTask">The parent task from which parameters will be copied</param>
 /// <param name="linkingType">Controls the possible sharing with the reference task some data structures</param>
 protected SimulationTask(SimulationTask refTask, TaskLinkingType linkingType) : this(refTask.id, refTask, linkingType)
 {
 }
コード例 #6
0
 /// <summary>
 /// Tells if a task is used at all or not.
 /// A task can be used generically for some phase type,
 /// as a master task for other tasks,
 /// or as a specific task for a phase.
 /// </summary>
 /// <param name="task">A task</param>
 /// <returns>true if the task is used, false otherwise</returns>
 public bool TaskIsUsed(SimulationTask task)
 {
     return((task.PhaseTypes.Count > 0) || task.MasterTasks.Any() || this.scenario.Phases.Any(p => p.Tasks.ContainsKey(task.Id)));
 }
コード例 #7
0
        protected internal virtual bool LoadFromXml(XElement xmlTask)
        {        //TODO: Error messages
            XAttribute attr;

            this.name     = (attr = xmlTask.Attribute("name")) == null ? String.Empty : attr.Value;
            this.TaskType = xmlTask.Attribute("taskType").ParseInteger();
            //this.systemTask = (attr = xmlTask.Attribute("systemTask")) == null ? false : attr.Value.ParseBoolean();
            this.autoExpandToAllCrewmen = (attr = xmlTask.Attribute("autoAssignToAllCrewMembers")) == null ? false : attr.Value.ParseBoolean();
            this.RelativeDate           = (attr = xmlTask.Attribute("relativeDate")) == null ? RelativeDateType.Undefined : SimulationTask.ParseRelativeDateType(attr.Value);
            this.StartDate = XmlIO.ParseTimeDistribution(xmlTask.Attribute("startDateUnit"),
                                                         xmlTask.Attribute("startDateMin"), xmlTask.Attribute("startDateMean"), xmlTask.Attribute("startDateMax"));
            if (this.relativeDate == RelativeDateType.Frequency)
            {
                this.DateOffset = XmlIO.ParseTimeDistribution(xmlTask.Attribute("dateOffsetUnit"),
                                                              xmlTask.Attribute("dateOffsetMin"), xmlTask.Attribute("dateOffsetMean"), xmlTask.Attribute("dateOffsetMax"));
            }
            this.relativeTime   = xmlTask.Attribute("relativeTime").ParseRelativeTimeType();
            this.DailyHourStart = xmlTask.Attribute("workingHourStart").ParseSimulationTime(TimeUnit.Hours);
            this.DailyHourEnd   = xmlTask.Attribute("workingHourEnd").ParseSimulationTime(TimeUnit.Hours);
            this.onHolidays     = xmlTask.Attribute("onHolidays").ParseBoolean();
            this.enabled        = (attr = xmlTask.Attribute("enabled")) == null ? true : attr.ParseBoolean();
            this.Duration       = XmlIO.ParseTimeDistribution(xmlTask.Attribute("taskDurationUnit"),
                                                              xmlTask.Attribute("taskDurationMin"), xmlTask.Attribute("taskDurationMean"), xmlTask.Attribute("taskDurationMax"));
            attr = xmlTask.Attribute("taskInterruptionPolicy");
            if (attr == null)
            {
                this.taskInterruptionPolicy = TaskInterruptionPolicies.ContinueOrResumeWithoutError;                            //Back compatibility behaviour
            }
            else
            {
                this.taskInterruptionPolicy = attr.ParseTaskInterruptionPolicy();
            }
            attr = xmlTask.Attribute("phaseInterruptionPolicy");
            if (attr == null)
            {
                attr = xmlTask.Attribute("interruptibility");                   //Backward compatibility
                if (attr == null)
                {
                    attr = xmlTask.Attribute("interruptability");                               //Spelling compatibility
                }
            }
            this.phaseInterruptionPolicy = attr.ParsePhaseInterruptionPolicy();
            attr = xmlTask.Attribute("scenarioInterruptionPolicy");
            if (attr == null)
            {
                this.scenarioInterruptionPolicy = ScenarioInterruptionPolicies.DropWithoutError;                                //Back compatibility behaviour
            }
            else
            {
                this.scenarioInterruptionPolicy = attr.ParseScenarioInterruptionPolicy();
            }
            this.priority = xmlTask.Attribute("priority").ParseInteger();
            this.numberOfCrewmenNeeded = xmlTask.Attribute("numberOfCrewMembersNeeded").ParseInteger();
            if ((attr = xmlTask.Attribute("rotation")) != null)
            {
                this.Rotation = new SimulationTime(TimeUnit.Hours, Math.Min(24.0, Math.Max(0.0, attr.Value.ParseReal())));
            }
            else if ((attr = xmlTask.Attribute("isRotating")) != null)                                 //Compatibility
            {
                this.Rotation = new SimulationTime(TimeUnit.Hours, attr.Value.ParseBoolean() ? 6 : 0); //Previously hard-coded to 6-hour rotation
            }
            else
            {
                this.Rotation = SimulationTime.Zero;
            }
            XElement elem;

            this.description = (elem = xmlTask.Element("description")) == null ? String.Empty : elem.Value;
            elem             = xmlTask.Element("phaseTypes");
            if (elem != null)
            {
                foreach (var phaseTypeRef in elem.Elements("PhaseTypeRef"))
                {
                    attr = phaseTypeRef.Attribute("refCode");
                    if (attr != null)
                    {
                        this.phaseTypes.Add(attr.Value.ParseInteger());
                    }
                }
            }
            elem = xmlTask.Element("crewMemberTypes");
            if (elem != null)
            {
                foreach (var phaseTypeRef in elem.Elements("CrewMemberTypeRef"))
                {
                    attr = phaseTypeRef.Attribute("refCode");
                    if (attr != null)
                    {
                        this.crewmanTypes.Add(attr.Value.ParseInteger());
                    }
                }
            }
            attr = xmlTask.Attribute("taskDuplicatesPolicy");
            if (attr == null)
            {
                this.NoDuplicate = (attr = xmlTask.Attribute("noDuplicate")) == null ? false : attr.Value.ParseBoolean();                               //Back compatibility behaviour
            }
            else
            {
                this.duplicatesPolicy = attr.ParseTaskDuplicatesPolicy();
            }
            //Task relations are loaded by TaskDictionary
            return(true);
        }
コード例 #8
0
 public TaskRelation(SimulationTask task1, RelationType relation, SimulationTask task2)
 {
     this.task1    = task1;
     this.relation = relation;
     this.task2    = task2;
 }
コード例 #9
0
 public TaskRelationTemp(SimulationTask task1, TaskRelation.RelationType relation, int taskId2)
 {
     this.task1    = task1;
     this.relation = relation;
     this.taskId2  = taskId2;
 }