public Node(string mark) { this.mark = mark; arrIn = new Act[0]; arrOut = new Act[0]; }
public Bitmap GetHuntDiagram(int width, int height) { if (width == -1) { width = 300; } if (height == -1) { height = 300; } int margin = 40, lineWidth = 5, fontSize = 9, markSpace = 5; ArrayList listAct = new ArrayList(arrAct); ActComparerByTime comparer = new ActComparerByTime(); listAct.Sort(comparer); Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); float yDelta = (height - 2 * margin) / listAct.Count; float tMax = GetDuration(); float xDelta = (width - 2 * margin) / tMax; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; Font f = new Font("Arial", fontSize); Pen p = new Pen(Color.Green, lineWidth); g.Clear(Color.White); ArrayList listXMark = new ArrayList(); for (int i = 0; i < listAct.Count; i++) { Act a = (Act)listAct[i]; int x1 = (int)(a.t * xDelta + margin); int x2 = (int)((a.t + a.dur) * xDelta + margin); int y = (int)(height - ((i + 1) * yDelta + margin)); g.DrawLine(p, x1, y, x2, y); g.DrawString(a.Start.mark.ToString(), f, Brushes.Blue, x1 - markSpace, y, sf); g.DrawString(a.End.mark.ToString(), f, Brushes.Blue, x2 + markSpace, y, sf); if (listXMark.Contains(a.t) == false) { listXMark.Add(a.t); } if (listXMark.Contains(a.t + a.dur) == false) { listXMark.Add(a.t + a.dur); } g.DrawString(a.mark, f, Brushes.Blue, margin / 2, y, sf); g.DrawLine(Pens.Black, x1, height - margin - 2, x1, height - margin + 2); g.DrawLine(Pens.Black, x2, height - margin - 2, x2, height - margin + 2); } listXMark.Sort(); foreach (float t in listXMark) { int x = (int)(t * xDelta + margin); int y = height - margin / 2; g.DrawString(t.ToString(), f, Brushes.Blue, x, y, sf); } g.DrawLine(Pens.Black, margin, height - margin, width - margin, height - margin); g.DrawLine(Pens.Black, margin, height - margin, margin, margin); g.DrawString("Линейная диаграмма", f, Brushes.Black, width / 2, margin / 2, sf); return(bmp); }
public void BuildActNet() { // матрица предшествования FillMP(); ArrayList list = new ArrayList(arrAct); ActComparerByPrevActs comparer = new ActComparerByPrevActs(arrAct, mP); list.Sort(comparer); arrAct = (Act[])list.ToArray(typeof(Act)); FillMP(); SetPi(); SetRo(); // создание вершин ArrayList listNode = new ArrayList(); Node[] arrNodePi = new Node[piCount]; for (int i = 0; i < piCount; i++) { arrNodePi[i] = new Node(string.Format("π{0}", i)); listNode.Add(arrNodePi[i]); } Node[] arrNodeRo = new Node[roCount]; for (int i = 0; i < roCount; i++) { arrNodeRo[i] = new Node(string.Format("ρ{0}", i + 1)); listNode.Add(arrNodeRo[i]); } arrNode = (Node[])listNode.ToArray(typeof(Node)); // связывание событий и работ for (int i = 0; i < arrAct.Length; i++) { arrAct[i].Start = arrNodePi[arrPi[i]]; arrAct[i].End = arrNodeRo[arrRo[i]]; } // фиктивные работы ArrayList listFa = new ArrayList(); for (int pi = 0; pi < piCount; pi++) { int i; for (i = 0; i < arrPi.Length; i++) { if (arrPi[i] == pi) { break; } } for (int j = 0; j < arrAct.Length; j++) { if (mP[i, j] == true) { Act fa = new Act("fict" + listFa.Count.ToString(), 0, null, null); fa.Start = arrNodeRo[arrRo[j]]; fa.End = arrNodePi[pi]; listFa.Add(fa); } } } Act[] res = new Act[arrAct.Length + listFa.Count]; arrAct.CopyTo(res, 0); listFa.CopyTo(res, arrAct.Length); arrAct = res; ArrayList listAct = new ArrayList(res); // удаление ненужных фикт. работ foreach (Act fa in listFa) { if (GetPaths(fa.Start, fa.End).Length > 1) { fa.Start.DelOutAct(fa); fa.End.DelInAct(fa); listAct.Remove(fa); } } arrAct = (Act[])listAct.ToArray(typeof(Act)); /*// "склеивание" событий (если из события выходят все фикт. работы) * foreach (Node n in arrNode) * { * bool canJoin = true; * foreach (Act a in n.arrOut) * if (a.dur != 0 || a.End.arrIn.Length != 1) * { * canJoin = false; * break; * } * if (canJoin == false || n.arrOut.Length == 0) * continue; * * Act[] arrOut = n.arrOut; * n.arrOut = new Act[0]; * foreach (Act fa in arrOut) * { * foreach (Act a in fa.End.arrOut) * a.Start = n; * foreach (Act a in fa.End.arrIn) * { * if (a == fa) * continue; * a.End = n; * } * listAct.Remove(fa); * listNode.Remove(fa.End); * fa.End.arrIn = new Act[0]; * fa.End.arrOut = new Act[0]; * } * } * arrNode = (Node[])listNode.ToArray(typeof(Node)); * arrAct = (Act[])listAct.ToArray(typeof(Act));*/ // "склеивание" событий (из вершины выходит только одна фикт. работа) foreach (Node n in arrNode) { if (n.arrOut.Length != 1 || n.arrOut[0].dur != 0) { continue; } Act[] arrOut = n.arrOut; n.arrOut = new Act[0]; Act fa = arrOut[0]; foreach (Act a in fa.End.arrOut) { a.Start = n; } foreach (Act a in fa.End.arrIn) { if (a == fa) { continue; } a.End = n; } listAct.Remove(fa); listNode.Remove(fa.End); fa.End.arrIn = new Act[0]; fa.End.arrOut = new Act[0]; } arrNode = (Node[])listNode.ToArray(typeof(Node)); arrAct = (Act[])listAct.ToArray(typeof(Act)); // "склеивание" событий (в вершину входит только одна фикт. работа) foreach (Node n in arrNode) { if (n.arrIn.Length != 1 || n.arrIn[0].dur != 0) { continue; } Act[] arrIn = n.arrIn; n.arrIn = new Act[0]; Act fa = arrIn[0]; foreach (Act a in fa.Start.arrIn) { a.End = n; } foreach (Act a in fa.Start.arrOut) { if (a == fa) { continue; } a.Start = n; } listAct.Remove(fa); listNode.Remove(fa.Start); fa.Start.arrIn = new Act[0]; fa.Start.arrOut = new Act[0]; } arrNode = (Node[])listNode.ToArray(typeof(Node)); arrAct = (Act[])listAct.ToArray(typeof(Act)); // ввод фиктивных событий для параллельных работ foreach (Act a1 in arrAct) { foreach (Act a2 in arrAct) { if (a1.Start == a2.Start && a1.End == a2.End && a1 != a2) { Node n = new Node("fict"); Act fa = new Act("fict" + listAct.Count.ToString(), 0, null, null); a2.End.DelInAct(a2); a2.End = n; fa.Start = n; fa.End = a1.End; listNode.Add(n); listAct.Add(fa); } } } arrAct = (Act[])listAct.ToArray(typeof(Act)); arrNode = (Node[])listNode.ToArray(typeof(Node)); // расчет временных параметров CalcStaticTimeParams(); // именование и сортировка событий по Te NodeComparerByTe ncomparer = new NodeComparerByTe(); listNode.Sort(ncomparer); arrNode = (Node[])listNode.ToArray(typeof(Node)); for (int i = 0; i < arrNode.Length; i++) { arrNode[i].mark = i.ToString(); } }