/// <summary> /// /// </summary> public void CreateEdge(int parentID, int childID) { TaskNode parent = Nodes.Find(x => x.ID == parentID); TaskNode child = Nodes.Find(x => x.ID == childID); CreateEdge(parent, child); }
public static TaskGraph CreateGraphFromFile() { string[] lines = System.IO.File.ReadAllLines(@"rand3500.stg"); TaskGraph loadedGraph = new TaskGraph(); Dictionary <TaskNode, IEnumerable <string> > dependencies = new Dictionary <TaskNode, IEnumerable <string> >(); for (int i = 1; i < lines.Count(); i++) { var line = lines[i]; if (line.StartsWith("#")) { break; } var lineItems = line.Split(null as char[], StringSplitOptions.RemoveEmptyEntries); int ID = 0; int weight = 0; if (!int.TryParse(lineItems[0], out ID)) { Console.WriteLine("Wrong graph format, ID cannot be parsed"); } if (!int.TryParse(lineItems[1], out weight)) { Console.WriteLine("Wrong graph format, Weight cannot be parsed"); } var predecessors = lineItems.Skip(3).ToArray(); //foreach (var item in predecessors) { // Console.WriteLine(item); //} var newTaskNode = new TaskNode(ID, weight * 10); dependencies[newTaskNode] = predecessors; loadedGraph.AddNode(newTaskNode); } foreach (var taskDependencies in dependencies) { foreach (var dependency in taskDependencies.Value) { int predecessor = 0; if (!int.TryParse(dependency, out predecessor)) { Console.WriteLine("Wrong graph format, Predecessor cannot be parsed"); } loadedGraph.CreateEdge(predecessor, taskDependencies.Key.ID); } } return(loadedGraph); }
/// <summary> /// Copy constructor /// </summary> private TaskNode(TaskNode prevTask, Dictionary <int, TaskNode> visited) { ID = prevTask.ID; visited.Add(ID, this); SimulatedExecutionTime = prevTask.SimulatedExecutionTime; parentNodes = prevTask.ParentNodes.Clone(visited); childNodes = prevTask.ChildNodes.Clone(visited); tLevel = prevTask.tLevel; slLevel = prevTask.slLevel; Status = BuildStatus.None; ReadySignal = new ManualResetEvent(false); }
public TaskNode Clone(Dictionary <int, TaskNode> visited) { if (visited.ContainsKey(this.ID)) { return(visited[this.ID]); } else { var taskCopy = new TaskNode(this, visited); //visited.Add(taskCopy.ID, taskCopy); return(taskCopy); } }
public DirectedEdge(TaskNode n1, TaskNode n2) { this.parent = n1; this.child = n2; }
public WorkSlot(int start, int end, TaskNode task) : base(start, end) { TaskToBeExecuted = task; }
public IdleSlot(int start, int end, TaskNode nextTask) : base(start, end) { NextExecutableTask = nextTask; }
public void AddIdleTime(int start, int end, TaskNode nextTask) { taskList.Add(new IdleSlot(start, end, nextTask)); }
public void AddTask(int start, int end, TaskNode task) { taskList.Add(new WorkSlot(start, end, task)); }
/// <summary> /// /// </summary> public void CreateEdge(TaskNode parent, TaskNode child) { Edges.Add(new DirectedEdge(parent, child)); parent.AddChild(child); child.AddParent(parent); }
public void AddNode(TaskNode newNode) { Nodes.Add(newNode); }
/// <summary> /// /// </summary> public void AddChild(TaskNode child) { childNodes.Add(child); }
/// <summary> /// /// </summary> public void AddParent(TaskNode parent) { parentNodes.Add(parent); }