Esempio n. 1
0
 public Packet(SystemVertex t, TaskVertex data, int time, double w)
 {
     target = t;
     this.timeArrived = time;
     this.data = data;
     weight = w;
 }
Esempio n. 2
0
 public int ComparerLab2(TaskVertex a, TaskVertex b)
 {
     if (a.maxNodes / maxNodes + a.maxWeight / maxWeight > b.maxNodes / maxNodes + b.maxWeight / maxWeight)
     {
         return -1;
     }
     else if (a.maxNodes / maxNodes + a.maxWeight / maxWeight < b.maxNodes / maxNodes + b.maxWeight / maxWeight)
     {
         return 1;
     }
     return 0;
 }
Esempio n. 3
0
 public int ComparerLab3(TaskVertex a, TaskVertex b)
 {
     if (a.NodesFromStart > b.NodesFromStart)
     {
         return 1;
     }
     else if (a.NodesFromStart < b.NodesFromStart)
     {
         return -1;
     }
     else if (vm.Graph.InEdges(a).Count() + vm.Graph.OutEdges(a).Count() > vm.Graph.InEdges(b).Count() + vm.Graph.OutEdges(b).Count())
     {
         return -1;
     }
     else if (vm.Graph.InEdges(a).Count() + vm.Graph.OutEdges(a).Count() < vm.Graph.InEdges(b).Count() + vm.Graph.OutEdges(b).Count())
     {
         return 1;
     }
     return 0;
 }
Esempio n. 4
0
        public void Assign(SystemVertex proc, TaskVertex task, int time)
        {
            this.time = time;
            if (this != proc)
            {

                foreach (var item in model.Graph.InEdges(task))
                {
                    //if (data.Contains(item.Source) && !proc.data.Contains(item.Source))
                    if (data.Contains(item.Source))
                    {
                        Packet packet = new Packet(proc, item.Source, 0, double.Parse(item.ID));
                        packets.Add(packet);
                    }
                }
                return;
            }

            data2.Clear();
            this.task = task;
            dataNeeded.Clear();
            isFree = false;

            var edges = model.Graph.InEdges(task);
            foreach (var edge in edges)
            {
                dataNeeded.Add(edge.Source);
            }

            if (dataNeeded.Count == 0)
            {
                scheduler.logs.Add("0.0." + time + "." + task.ID + "." + this.ID);
                isCalculating = true;
                calcStarted = time;
            }
            else
            {
                CheckData(time);
            }
        }
Esempio n. 5
0
        //Open Graph
        private void LoadGraph_OnClick(object sender, RoutedEventArgs e)
        {
            FileDialog dialog = new OpenFileDialog();
            dialog.DefaultExt = ".xml";
            dialog.Filter = "XML Documents (.xml)|*.xml";
            bool? result = dialog.ShowDialog();
            if (result != true)
            {
                return;
            }
            string path = dialog.FileName;
            TaskGraph graph = new TaskGraph(true);
            XmlDocument document = new XmlDocument();
            document.LoadXml(File.ReadAllText(path));
            XmlNodeList vertices = document.GetElementsByTagName("vertice");
            XmlNodeList edges = document.GetElementsByTagName("edge");
            foreach (XmlNode node in vertices)
            {
                TaskVertex vertex = new TaskVertex(node.Attributes[0].Value, node.Attributes[1].Value);
                graph.AddVertex(vertex);
            }

            foreach (XmlNode node in edges)
            {
                var source = graph.Vertices.First(x => x.ID == node.Attributes[1].Value);
                var target = graph.Vertices.First(x => x.ID == node.Attributes[2].Value);
                TaskEdge edge = new TaskEdge(node.Attributes[0].Value, source, target);
                graph.AddEdge(edge);
            }

            vm.Graph = graph;
        }
Esempio n. 6
0
        //Checking if Graph has cycle
        bool HasCycle(TaskVertex vertex)
        {
            if (root.Contains(vertex))
            {
                return true;
            }
            root.Add(vertex);
            var outEdges = vm.Graph.OutEdges(vertex);
            foreach (var outEdge in outEdges)
            {
                var childVertex = outEdge.Target;
                if (HasCycle(childVertex))
                {
                    return true;
                }

            }
            root.Remove(vertex);
            return false;
        }
Esempio n. 7
0
        /// <summary>
        /// Method that makes DFS and calculates different coefficients
        /// </summary>
        /// <param name="origin">vertex from where started method Calculate</param>
        /// <param name="currentVertex">vertex in which the cursor is now</param>
        /// <param name="depth">depth of root from start</param>
        /// <param name="time">time from start</param>
        private void Calculate(TaskVertex origin, TaskVertex currentVertex, int depth, int time)
        {
            //Lab2
            origin.CriticalNodes++;
            origin.CriticalWeight += int.Parse(currentVertex.Weight);

            //Lab3
            currentVertex.NodesFromStart = depth;

            //Lab4
            currentVertex.TimeFromStart = time;

            if (origin.maxNodes > maxNodes)
            {
                maxNodes = origin.maxNodes;
            }
            if (origin.maxWeight > maxWeight)
            {
                maxWeight = origin.maxWeight;
            }
            var outEdges = vm.Graph.OutEdges(currentVertex);
            foreach (var outEdge in outEdges)
            {
                Calculate(origin, outEdge.Target, depth + 1, currentVertex.TimeFromStart);
            }
            origin.CriticalWeight -= int.Parse(currentVertex.Weight);
            origin.CriticalNodes--;
        }
Esempio n. 8
0
 public int ComparerLab4(TaskVertex a, TaskVertex b)
 {
     if (a.TimeFromStart > b.TimeFromStart)
     {
         return 1;
     }
     else if (a.TimeFromStart < b.TimeFromStart)
     {
         return -1;
     }
     return 0;
 }