Пример #1
0
 public void SaveModFile(string fileName)
 {
     using (StreamWriter writer = new StreamWriter(fileName))
     {
         writer.WriteLine("t nodes");
         foreach (var nodeI in Nodes.ValidIndexies())
         {
             var node = Nodes[nodeI];
             if (node.Modified)
             {
                 WriteNode(writer, node);
             }
         }
         writer.WriteLine("t links");
         foreach (var linkI in Links.ValidIndexes())
         {
             foreach (var linkJ in Links.ValidIndexes(linkI))
             {
                 var link = Links[linkI, linkJ];
                 if (link.Modified)
                 {
                     WriteLink(writer, link);
                 }
             }
         }
     }
 }
Пример #2
0
 public void IterationFinished(int iteration)
 {
     // only run on the last iteration
     // Important for not saving too much data
     if (iteration == Root.TotalIterations - 1)
     {
         var dir = Path.GetDirectoryName(FileName);
         if (dir != null)
         {
             DirectoryInfo dirInfo = new DirectoryInfo(dir);
             if (!dirInfo.Exists)
             {
                 dirInfo.Create();
             }
         }
         using (StreamWriter Writer = new StreamWriter(FileName))
         {
             if (SaveOD)
             {
                 Writer.WriteLine("OriginZone,DestinationZone,TripPurpose,NumberOfOccurrences");
                 foreach (var origin in ODPurposeDictionary.ValidIndexes())
                 {
                     var originStr = origin.ToString();
                     foreach (var destintation in ODPurposeDictionary.ValidIndexes(origin))
                     {
                         var destStr    = destintation.ToString();
                         var dictionary = ODPurposeDictionary[origin, destintation];
                         if (dictionary != null)
                         {
                             foreach (var pair in dictionary)
                             {
                                 Writer.WriteLine("{0},{1},{2},{3}", originStr, destStr, pair.Key, pair.Value);
                             }
                         }
                     }
                 }
             }
             else
             {
                 Writer.WriteLine("Trip Purpose, Number of Occurrences");
                 foreach (var pair in PurposeDictionary)
                 {
                     Writer.WriteLine("{0}, {1}", pair.Key, pair.Value);
                 }
             }
         }
     }
 }
Пример #3
0
 private static void SaveMatrix(SparseTwinIndex <float> matrix, string fileName)
 {
     using (StreamWriter writer = new StreamWriter(fileName))
     {
         var header = true;
         foreach (var i in matrix.ValidIndexes())
         {
             var first = true;
             if (header)
             {
                 header = false;
                 foreach (var j in matrix.ValidIndexes(i))
                 {
                     if (first)
                     {
                         first = false;
                         writer.Write("Zones O\\D,");
                         writer.Write(j);
                     }
                     else
                     {
                         writer.Write(',');
                         writer.Write(j);
                     }
                 }
                 writer.WriteLine();
                 first = true;
             }
             foreach (var j in matrix.ValidIndexes(i))
             {
                 if (first)
                 {
                     first = false;
                     writer.Write(i);
                     writer.Write(',');
                     writer.Write(matrix[i, j]);
                 }
                 else
                 {
                     writer.Write(",");
                     writer.Write(matrix[i, j]);
                 }
             }
             writer.WriteLine();
         }
     }
 }
Пример #4
0
 public static void SaveMatrixThirdNormalized(SparseTwinIndex <float> matrix, FileLocation saveLocation)
 {
     using (StreamWriter writer = new StreamWriter(saveLocation))
     {
         writer.WriteLine("Origin,Destination,Data");
         foreach (var o in matrix.ValidIndexes())
         {
             foreach (var d in matrix.ValidIndexes(o))
             {
                 writer.Write(o);
                 writer.Write(',');
                 writer.Write(d);
                 writer.Write(',');
                 writer.WriteLine(matrix[o, d]);
             }
         }
     }
 }
Пример #5
0
 public static void SaveMatrixThirdNormalized(SparseTwinIndex<float> matrix, FileLocation saveLocation)
 {
     using (StreamWriter writer = new StreamWriter(saveLocation))
     {
         writer.WriteLine("Origin,Destination,Data");
         foreach (var o in matrix.ValidIndexes())
         {
             foreach (var d in matrix.ValidIndexes(o))
             {
                 writer.Write(o);
                 writer.Write(',');
                 writer.Write(d);
                 writer.Write(',');
                 writer.WriteLine(matrix[o, d]);
             }
         }
     }
 }
Пример #6
0
 private static void SaveMatrix(SparseTwinIndex<float> matrix, string fileName)
 {
     using ( StreamWriter writer = new StreamWriter( fileName ) )
     {
         var header = true;
         foreach ( var i in matrix.ValidIndexes() )
         {
             var first = true;
             if ( header )
             {
                 header = false;
                 foreach ( var j in matrix.ValidIndexes( i ) )
                 {
                     if ( first )
                     {
                         first = false;
                         writer.Write( "Zones O\\D," );
                         writer.Write( j );
                     }
                     else
                     {
                         writer.Write( ',' );
                         writer.Write( j );
                     }
                 }
                 writer.WriteLine();
                 first = true;
             }
             foreach ( var j in matrix.ValidIndexes( i ) )
             {
                 if ( first )
                 {
                     first = false;
                     writer.Write( i );
                     writer.Write( ',' );
                     writer.Write( matrix[i, j] );
                 }
                 else
                 {
                     writer.Write( "," );
                     writer.Write( matrix[i, j] );
                 }
             }
             writer.WriteLine();
         }
     }
 }