public SupplyTask(float _startTime, Transportation _transportation, DemandPoint _demandPoint, Path _path) { StartTime = _startTime; EndTime = 0f; transportation = _transportation; demandPoint = _demandPoint; path = _path; }
public SupplyCenter(int _position, int[] _transportations, HeadQuater headQuater) { Position = _position; for (int i = 0; i < _transportations.Length; i++) { TransportationType type = (TransportationType)i; Transportations.Add(type, new List <Transportation>[] { new List <Transportation>(), new List <Transportation>() }); for (int j = 0; j < _transportations[i]; j++) { Transportation newTp = Transportation.GetTransportation(type); Transportations[type][0].Add(newTp); headQuater.RegisterTransportation(newTp); } } }
public bool Schedule(Map map, Dictionary <int, DemandPoint> DemandPoints) { foreach (Task t in rawTasks) { float time = t.time; Transportation tp; TransportationType ty = t.transportationType; List <SupplyTask> OnGoingTasks = new List <SupplyTask>(); if (Transportations[ty][0].Count > 0) { tp = Transportations[ty][0][0]; Transportations[ty][1].Add(tp); Transportations[ty][0].RemoveAt(0); SupplyTask newTask = new SupplyTask(time, tp, DemandPoints[t.dp], map.GetPath(t.path)); OnGoingTasks.Add(newTask); Tasks.Add(newTask); } else { Transportation lastFreedTp = null; for (int i = OnGoingTasks.Count - 1; i >= 0; i--) { SupplyTask st = OnGoingTasks[i]; if (st.EstimateReturnTime() > time) { Transportation freedTp = lastFreedTp = st.GetTransportation(); OnGoingTasks.RemoveAt(i); Transportations[freedTp.Type][0].Add(freedTp); Transportations[freedTp.Type][1].Remove(freedTp); } } if (lastFreedTp == null) { return(false); } SupplyTask newTask = new SupplyTask(time, lastFreedTp, DemandPoints[t.dp], map.GetPath(t.path)); OnGoingTasks.Add(newTask); Tasks.Add(newTask); } } IsScheduled = true; ResetQueue(); return(true); }
public void RegisterTransportation(Transportation _tp) { Transportations.Add(_tp); }
private void TaskFinished(Transportation freedTp) { Transportations[freedTp.Type][0].Add(freedTp); Transportations[freedTp.Type][1].Remove(freedTp); }