/// <summary> /// Constructor of a flow graph /// </summary> /// <param name="persons">List of persons</param> /// <param name="slots">List of scheduleslots</param> /// <param name="start">Date of the first day of the week to generate</param> public FlowGraph(List <Person> persons, List <ScheduleSlot> slots, DateTime start) { this.Source = new FlowNode("Source"); this.Target = new FlowNode("Target"); this.Nodes = new List <FlowNode>(); this.Arcs = new List <FlowArc>(); this.WeekStart = start; // creating person's nodes foreach (Person person in persons) { PersonFlowNode node = new PersonFlowNode(person); this.Nodes.Add(node); // link node to source this.Arcs.Add(new FlowArc(this.Source, node, Math.Round(person.occupancyRate * 40 / 100))); } // creating slots' nodes foreach (ScheduleSlot slot in slots) { SlotFlowNode node = new SlotFlowNode(slot); double delta = slot.endHour.Subtract(slot.startHour).TotalHours; this.Nodes.Add(node); // linking node to person's nodes foreach (FlowNode nody in this.Nodes) { if (nody.Type == FlowNodeType.Person) { this.Arcs.Add(new FlowArc(nody, node, delta)); } } // linking node to target this.Arcs.Add(new FlowArc(node, this.Target, delta * slot.minAttendency)); } }
public FlowGraph(List <Person> persons, List <ScheduleSlot> slots, DateTime start, List <AbsenceDemand> absences) { this.Source = new FlowNode("Source"); this.Target = new FlowNode("Target"); this.Nodes = new List <FlowNode>(); this.Arcs = new List <FlowArc>(); this.WeekStart = start; // creating person's nodes foreach (Person person in persons) { PersonFlowNode node = new PersonFlowNode(person); this.Nodes.Add(node); // link node to source this.Arcs.Add(new FlowArc(this.Source, node, Math.Round(person.occupancyRate * 40 / 100))); } // creating slots' nodes foreach (ScheduleSlot slot in this.SplitSlots(new List <ScheduleSlot>(slots), absences)) { SlotFlowNode node = new SlotFlowNode(slot); double delta = slot.endHour.Subtract(slot.startHour).TotalHours; this.Nodes.Add(node); // linking node to person's nodes foreach (FlowNode nody in this.Nodes) { if (nody.Type == FlowNodeType.Person) { bool present = true; // check absences for (int i = 0; i < absences.Count && present; i++) { AbsenceDemand absence = absences[i]; // if the absent is the concerned node then if (absence.Person == ((PersonFlowNode)nody).Person) { // gettting the 'real' day of the slot DateTime theDay = WeekStart.AddDays(((int)slot.dayOfWeek - (int)WeekStart.DayOfWeek) % 7); DateTime theStart = theDay.Add(slot.startHour); DateTime theEnd = theDay.Add(slot.endHour); // check for overlap if (theStart >= absence.start && theEnd <= absence.end) { present = false; } } } // only if no overlap has been found is the node linked if (present) { this.Arcs.Add(new FlowArc(nody, node, delta)); } } } // linking node to target this.Arcs.Add(new FlowArc(node, this.Target, delta * slot.minAttendency)); } }