public void load(List<string> textFile) { vertices = new Vertex[int.Parse(getDataFromLine(textFile[0], 1))]; if (vertices.Length == 0) throw new Exception("Zerowa liczba węzłów!"); for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vertex(i+1); } edges = new Edge[int.Parse(getDataFromLine(textFile[1], 1))]; if (edges.Length == 0) throw new Exception("Zerowa liczba łączy!"); for (int i = 0; i < edges.Length; i++) { int link_id = int.Parse(getDataFromLine(textFile[2 + i], 0)); int begin_id = int.Parse(getDataFromLine(textFile[2 + i], 1)); int end_id = int.Parse(getDataFromLine(textFile[2 + i], 2)); double capacity = double.Parse(getDataFromLine(textFile[2 + i], 3)); double price = double.Parse(getDataFromLine(textFile[2 + i], 4)); edges[i] = new Edge(link_id, vertices[begin_id - 1], vertices[end_id - 1], capacity, price); edges[i].Begin.addEdgeOut(edges[i]); } demands = new Demand[int.Parse(getDataFromLine(textFile[2 + edges.Length], 1))]; if (demands.Length == 0) throw new Exception("Zerowa liczba zapotrzebowań!"); for (int i = 0; i < demands.Length; i++) { int demand_id = int.Parse(getDataFromLine(textFile[3 + edges.Length + i], 0)); int begin_id = int.Parse(getDataFromLine(textFile[3 + edges.Length + i], 1)); int end_id = int.Parse(getDataFromLine(textFile[3 + edges.Length + i], 2)); double capacity = double.Parse(getDataFromLine(textFile[3 + edges.Length + i], 3)); demands[i] = new Demand(demand_id, vertices[begin_id - 1], vertices[end_id - 1], capacity); } }
public Demand(int id, Vertex begin, Vertex end, double weight) { this.id = id; this.begin = begin; this.end = end; this.capacity = weight; }
static private void generateRandomPath(Model.Demand demand) { Random generator = new Random(); Model.Vertex begin = demand.Begin; Model.Vertex end = demand.End; new_network.resetVertices(); //Console.WriteLine("Żądanie: " + demand.Begin.Id + " " + demand.End.Id); //demand.Path = new Stack<Model.Edge>(); //Model.Vertex currentVertex = begin; //do //{ // Model.Edge currentEdge = currentVertex.getRandomEdgeOut(); // if (!currentVertex.Visited && currentEdge != null) // { // currentVertex.Visited = true; // demand.Path.Push(currentEdge); // currentVertex = currentEdge.End; // Console.WriteLine(currentEdge.Begin.Id + " -> " + currentEdge.End.Id); // } // else // { // currentVertex.Visited = true; // Model.Vertex tmp = currentVertex; // currentVertex = demand.Path.Pop().Begin; // currentVertex.Visited = false; // Console.WriteLine(currentVertex.Id + " <- " + tmp.Id); // } //} while (demand.Path.Peek().End != end); Stack <Model.Vertex> path = new Stack <Model.Vertex>(); demand.Path = new Stack <Model.Edge>(); path.Push(begin); while (path.Peek() != end) { Model.Vertex currentVertex = path.Peek(); Model.Edge currentEdge = currentVertex.getRandomEdgeOut(); if (!currentVertex.Visited && currentEdge != null) { //Console.WriteLine(currentEdge.Begin.Id + " -> " + currentEdge.End.Id); demand.Path.Push(currentEdge); path.Push(currentEdge.End); } else { demand.Path.Pop(); path.Pop(); Model.Vertex tmp = path.Peek(); //Console.WriteLine(tmp.Id + " <- " + currentVertex.Id); path.Peek().Visited = false; } currentVertex.Visited = true; } }