Exemplo n.º 1
0
 // Writes the solution in a file
 void WriteSolution(string fileName)
 {
     using (StreamWriter output = new StreamWriter(fileName))
     {
         output.WriteLine(knapsackValue.GetValue());
         for (int i = 0; i < solutions.Count; ++i)
         {
             output.Write(solutions[i] + " ");
         }
         output.WriteLine();
     }
 }
Exemplo n.º 2
0
 // Writes the solution in a file with the following format :
 //  - number of trucks used and total distance
 //  - for each truck the nodes visited (omitting the start/end at the depot)
 void WriteSolution(string fileName)
 {
     using (StreamWriter output = new StreamWriter(fileName))
     {
         output.WriteLine(nbTrucksUsed.GetValue() + " " + totalDistance.GetValue());
         for (int k = 0; k < nbTrucks; k++)
         {
             if (trucksUsed[k].GetValue() != 1)
             {
                 continue;
             }
             // Values in sequence are in [0..nbCustomers-1]. +2 is to put it back in [2..nbCustomers+1]
             // as in the data files (1 being the depot)
             LSCollection customersCollection = customersSequences[k].GetCollectionValue();
             for (int i = 0; i < customersCollection.Count(); i++)
             {
                 output.Write((customersCollection[i] + 2) + " ");
             }
             output.WriteLine();
         }
     }
 }