Exemple #1
0
 private void WriteGenerationFile(float totalProduction, float totalAttraction)
 {
     if (!string.IsNullOrEmpty(GenerationOutputFileName))
     {
         bool first = !File.Exists(GenerationOutputFileName);
         // make sure the directory exists
         var dir = Path.GetDirectoryName(GenerationOutputFileName);
         if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         // if the file name exists try to write to it, appending
         using (StreamWriter writer = new StreamWriter(GenerationOutputFileName, true))
         {
             if (first)
             {
                 writer.WriteLine("Age,Employment,Occupation,Mobility,Production,Attraction,WAH");
             }
             writer.Write(AgeCategoryRange.ToString());
             writer.Write(',');
             writer.Write(EmploymentStatusCategory.ToString());
             writer.Write(',');
             writer.Write(OccupationCategory.ToString());
             writer.Write(',');
             writer.Write(Mobility.ToString());
             writer.Write(',');
             writer.Write(totalProduction);
             writer.Write(',');
             writer.Write(totalAttraction);
             writer.Write(',');
             writer.WriteLine(WorkAtHomeTotal);
         }
     }
 }
Exemple #2
0
 private void SaveGenerationData(float totalProduction)
 {
     if (!String.IsNullOrEmpty(GenerationOutputFileName))
     {
         bool first = !File.Exists(GenerationOutputFileName);
         // if the file name exists try to write to it, appending
         using (StreamWriter writer = new StreamWriter(GenerationOutputFileName, true))
         {
             if (first)
             {
                 writer.WriteLine("Age,Employment,Occupation,Mobility,Total");
             }
             writer.Write(AgeCategoryRange.ToString());
             writer.Write(',');
             writer.Write(EmploymentStatusCategory.ToString());
             writer.Write(',');
             writer.Write(OccupationCategory.ToString());
             writer.Write(',');
             writer.Write(Mobility.ToString());
             writer.Write(',');
             writer.WriteLine(totalProduction);
         }
     }
 }
Exemple #3
0
        private void WriteAttractionFile(SparseArray <float> attractions)
        {
            if (!AttractionFileName.ContainsFileName())
            {
                return;
            }
            var           flatAttractions = attractions.GetFlatData();
            bool          first           = !File.Exists(AttractionFileName.GetFileName());
            StringBuilder buildInside     = new StringBuilder();

            buildInside.Append(',');
            buildInside.Append(AgeCategoryRange.ToString());
            buildInside.Append(',');
            buildInside.Append(EmploymentStatusCategory.ToString());
            buildInside.Append(',');
            buildInside.Append(OccupationCategory.ToString());
            buildInside.Append(',');
            buildInside.Append(Mobility.ToString());
            buildInside.Append(',');
            string categoryData = buildInside.ToString();

            using (StreamWriter writer = new StreamWriter(AttractionFileName.GetFileName(), true))
            {
                if (first)
                {
                    // if we are the first thing to generate, then write the header as well
                    writer.WriteLine("Zone,Age,Employment,Occupation,Mobility,Attraction");
                }
                for (int i = 0; i < flatAttractions.Length; i++)
                {
                    writer.Write(attractions.GetSparseIndex(i));
                    writer.Write(categoryData);
                    writer.WriteLine(flatAttractions[i]);
                }
            }
        }