Ejemplo n.º 1
0
 public static CRoute GetRandomRouteForRequest(CRequest request, int index)  {
     List<CRoute> routes =
         CGlobalManager.GlobalRoutesList.Where(
             x => x.NodeBegin == request.StartNode && x.NodeFinish == request.EndNode).ToList();  //linq that takes all routes for this request
 
     Random rnd = new Random();
     int random = rnd.Next(routes.Count() - 1);
     CRoute randomRoute = routes.ElementAt(random); //we take random route 
     if (randomRoute.Index == index) //if index == previous route then find new route
     {
         routes.Remove(randomRoute);
         random = rnd.Next(routes.Count() - 1);
         randomRoute = routes.ElementAt(random);   
     }
    
     var slotsQuantity = randomRoute.DemandSlotMapping[request.Size]; //we are looking for slots quantity for this request size
     while (!randomRoute.TryAlocateSlots(slotsQuantity, request.Id)) //When there is no free slots we have to find new random route TODO: if no route will be found propably stack overflow
     {
     routes.Remove(randomRoute);
     if (!routes.Any()) //if there is no more routes then return null (that means it cannot allocate this request
      {
      return null;
      }
     random = rnd.Next(routes.Count() - 1);
     randomRoute = routes.ElementAt(random); //we take random route 
     slotsQuantity = randomRoute.DemandSlotMapping[request.Size];
     }
      return randomRoute;
  }
Ejemplo n.º 2
0
 private static CRequest GetRequestFromRow(string line,int requestId){
     int startNode = Int32.Parse(line.Substring(0, 3).Trim());
     int endNode = Int32.Parse(line.Substring(2, 3).Trim());
     int capacity = Int32.Parse(line.Substring(5).Trim());
     CRequest result = new CRequest(requestId,startNode, endNode, capacity);
     return result;
 }