コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 public DirectedEdge(TaskNode n1, TaskNode n2)
 {
     this.parent = n1;
     this.child  = n2;
 }
コード例 #6
0
 public WorkSlot(int start, int end, TaskNode task) : base(start, end)
 {
     TaskToBeExecuted = task;
 }
コード例 #7
0
 public IdleSlot(int start, int end, TaskNode nextTask) : base(start, end)
 {
     NextExecutableTask = nextTask;
 }
コード例 #8
0
 public void AddIdleTime(int start, int end, TaskNode nextTask)
 {
     taskList.Add(new IdleSlot(start, end, nextTask));
 }
コード例 #9
0
 public void AddTask(int start, int end, TaskNode task)
 {
     taskList.Add(new WorkSlot(start, end, task));
 }
コード例 #10
0
 /// <summary>
 ///
 /// </summary>
 public void CreateEdge(TaskNode parent, TaskNode child)
 {
     Edges.Add(new DirectedEdge(parent, child));
     parent.AddChild(child);
     child.AddParent(parent);
 }
コード例 #11
0
 public void AddNode(TaskNode newNode)
 {
     Nodes.Add(newNode);
 }
コード例 #12
0
 /// <summary>
 ///
 /// </summary>
 public void AddChild(TaskNode child)
 {
     childNodes.Add(child);
 }
コード例 #13
0
 /// <summary>
 ///
 /// </summary>
 public void AddParent(TaskNode parent)
 {
     parentNodes.Add(parent);
 }