コード例 #1
0
ファイル: TransitLines.cs プロジェクト: Cocotus/XTMF
 /// <summary>
 ///
 /// </summary>
 /// <param name="file621Name"></param>
 public TransitLines(string file621Name)
 {
     using ( StreamReader reader = new StreamReader( file621Name ) )
     {
         List<TransitLine> transitLines = new List<TransitLine>( 1000 );
         char[] split = new char[] { ',', ' ', '\t' };
         string line;
         // Process each line
         while ( ( line = reader.ReadLine() ) != null )
         {
             string[] parts = line.Split( split, StringSplitOptions.RemoveEmptyEntries );
             if ( parts.Length == 15 )
             {
                 TransitLine current = new TransitLine();
                 try
                 {
                     current.ID = new string[] { parts[0] };
                     current.Mode = parts[1][0];
                     current.VehicalType = int.Parse( parts[2] );
                     current.NumberOfVehicals = int.Parse( parts[3] );
                     current.MinHDWY = float.Parse( parts[4] );
                     current.Length = float.Parse( parts[5] );
                     current.Time = float.Parse( parts[6] );
                     current.Bordings = int.Parse( parts[7] );
                     if ( !float.TryParse( parts[8], out current.KMTraveled ) )
                     {
                         current.KMTraveled = float.PositiveInfinity;
                     }
                     if ( float.TryParse( parts[9], out current.HoursTraveled ) )
                     {
                         current.HoursTraveled = float.PositiveInfinity;
                     }
                     current.LoadAverage = float.Parse( parts[10] );
                     current.LoadMax = float.Parse( parts[11] );
                     current.MaxVolume = float.Parse( parts[12] );
                     current.OperationCosts = float.Parse( parts[13] );
                     current.EnergyConsumption = float.Parse( parts[14] );
                     transitLines.Add( current );
                 }
                 catch
                 {
                     StringBuilder errorMessage = new StringBuilder();
                     errorMessage.Append( "We had problems loading the transit lines file \"" );
                     errorMessage.Append( file621Name );
                     errorMessage.AppendLine( "\"." );
                     if ( current.ID != null && current.ID.Length > 0 )
                     {
                         errorMessage.Append( "The problem occurred while trying to read " );
                         errorMessage.Append( current.ID[0] );
                         errorMessage.AppendLine( "." );
                     }
                     throw new XTMF.XTMFRuntimeException( errorMessage.ToString() );
                 }
             }
         }
         this.Lines = transitLines.ToArray();
     }
     GC.Collect();
 }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file621Name"></param>
 public TransitLines(string file621Name)
 {
     using (StreamReader reader = new StreamReader(file621Name))
     {
         List <TransitLine> transitLines = new List <TransitLine>(1000);
         char[]             split        = new char[] { ',', ' ', '\t' };
         string             line;
         // Process each line
         while ((line = reader.ReadLine()) != null)
         {
             string[] parts = line.Split(split, StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length == 15)
             {
                 TransitLine current = new TransitLine();
                 try
                 {
                     current.ID               = new string[] { parts[0] };
                     current.Mode             = parts[1][0];
                     current.VehicalType      = int.Parse(parts[2]);
                     current.NumberOfVehicals = int.Parse(parts[3]);
                     current.MinHDWY          = float.Parse(parts[4]);
                     current.Length           = float.Parse(parts[5]);
                     current.Time             = float.Parse(parts[6]);
                     current.Bordings         = float.Parse(parts[7]);
                     if (!float.TryParse(parts[8], out current.KMTraveled))
                     {
                         current.KMTraveled = float.PositiveInfinity;
                     }
                     if (float.TryParse(parts[9], out current.HoursTraveled))
                     {
                         current.HoursTraveled = float.PositiveInfinity;
                     }
                     current.LoadAverage       = float.Parse(parts[10]);
                     current.LoadMax           = float.Parse(parts[11]);
                     current.MaxVolume         = float.Parse(parts[12]);
                     current.OperationCosts    = float.Parse(parts[13]);
                     current.EnergyConsumption = float.Parse(parts[14]);
                     transitLines.Add(current);
                 }
                 catch
                 {
                     StringBuilder errorMessage = new StringBuilder();
                     errorMessage.Append("We had problems loading the transit lines file \"");
                     errorMessage.Append(file621Name);
                     errorMessage.AppendLine("\".");
                     if (current.ID != null && current.ID.Length > 0)
                     {
                         errorMessage.Append("The problem occured while trying to read ");
                         errorMessage.Append(current.ID[0]);
                         errorMessage.AppendLine(".");
                     }
                     throw new XTMF.XTMFRuntimeException(errorMessage.ToString());
                 }
             }
         }
         this.Lines = transitLines.ToArray();
     }
     GC.Collect();
 }
コード例 #3
0
ファイル: CombinationTally.cs プロジェクト: Cocotus/XTMF
 public float ComputeError(ParameterSetting[] parameters, TransitLine[] truth, TransitLine[] predicted)
 {
     var first = this.FirstTally.ComputeError( parameters, truth, predicted );
     var second = this.SecondTally.ComputeError( parameters, truth, predicted );
     return ( first * FirstWeight ) + ( second * SecondWeight );
 }
コード例 #4
0
ファイル: NetworkAI.cs プロジェクト: Cocotus/XTMF
 public float ComplexErrorFunction(ParameterSetting[] parameters, TransitLine[] transitLine, TransitLine[] predicted, float[] aggToTruth)
 {
     float sum = 0;
     //var regionError = this.ComputeRegionError( transitLine, predicted );
     //var lineByLine = this.ComputeLineError( transitLine, aggToTruth );
     foreach ( var tally in this.ErrorTallies )
     {
         sum += tally.ComputeError( parameters, transitLine, predicted );
     }
     return sum;
 }
コード例 #5
0
ファイル: RegionErrorTally.cs プロジェクト: Cocotus/XTMF
 public float ComputeError(ParameterSetting[] parameters, TransitLine[] transitLine, TransitLine[] predicted)
 {
     List<Pair<char, char>> foundModes = new List<Pair<char, char>>();
     var ttsLines = transitLine.Length;
     var predictedLines = predicted.Length;
     var compairePair = new Pair<char, char>();
     for ( int i = 0; i < ttsLines; i++ )
     {
         if ( i > transitLine.Length )
         {
             throw new XTMFRuntimeException( String.Format( "i = {0}, ttsLines = {1}, transitLine.Length = {2}",
                 i, ttsLines, transitLine.Length ) );
         }
         var mode = transitLine[i].Mode;
         if ( transitLine[i].ID == null )
         {
             throw new XTMFRuntimeException( "There is a TTS line without an ID!" );
         }
         else if ( transitLine[i].ID.Length < 1 )
         {
             throw new XTMFRuntimeException( "There is a TTS line without an ID!" );
         }
         else if ( transitLine[i].ID[0].Length < 1 )
         {
             throw new XTMFRuntimeException( "There is an invalid ID for the TTS line #" + i + "!" );
         }
         var firstLetter = transitLine[i].ID[0][0];
         compairePair.First = mode;
         compairePair.Second = firstLetter;
         if ( !foundModes.Contains( compairePair ) )
         {
             foundModes.Add( new Pair<char, char>( mode, firstLetter ) );
         }
     }
     var numberOfModesFirstLetters = foundModes.Count;
     float[] aggTTSToMode = new float[numberOfModesFirstLetters];
     float[] aggPredToMode = new float[numberOfModesFirstLetters];
     // first pass agg all of the tts numbers
     var testPair = new Pair<char, char>();
     for ( int i = 0; i < ttsLines; i++ )
     {
         testPair.First = transitLine[i].Mode;
         testPair.Second = transitLine[i].ID[0][0];
         var indexOfTransitLine = foundModes.IndexOf( testPair );
         if ( indexOfTransitLine == -1 )
         {
             continue;
         }
         aggTTSToMode[indexOfTransitLine] += transitLine[i].Bordings;
     }
     // second pass agg all of the predicted numbers
     for ( int i = 0; i < predictedLines; i++ )
     {
         testPair.First = predicted[i].Mode;
         testPair.Second = predicted[i].ID[0][0];
         var indexOfPredictedMode = foundModes.IndexOf( testPair );
         if ( indexOfPredictedMode == -1 )
         {
             continue;
         }
         aggPredToMode[indexOfPredictedMode] += predicted[i].Bordings;
     }
     double rmse = 0;
     double mabs = 0;
     double terror = 0;
     for ( int i = 0; i < numberOfModesFirstLetters; i++ )
     {
         float error = this.RegionPercentError ? (float)( Math.Abs( aggPredToMode[i] - aggTTSToMode[i] ) / aggTTSToMode[i] ) : aggTTSToMode[i] - aggPredToMode[i];
         rmse += error * error;
         mabs += Math.Abs( error );
         terror += error;
     }
     var finalError = (float)( ( rmse * this.RMSEWeight ) + ( mabs * this.MABSWeight ) + ( terror * this.TERRORWeight ) );
     if ( !String.IsNullOrWhiteSpace( this.RegionErrorFile ) )
     {
         bool exists = File.Exists( this.RegionErrorFile );
         using ( var writer = new StreamWriter( this.RegionErrorFile, true ) )
         {
             if ( !exists )
             {
                 for ( int i = 0; i < numberOfModesFirstLetters; i++ )
                 {
                     writer.Write( foundModes[i].Second );
                     writer.Write( ':' );
                     writer.Write( foundModes[i].First );
                     if ( i == numberOfModesFirstLetters - 1 )
                     {
                         if ( this.RegionPercentError )
                         {
                             writer.WriteLine( ",%Error" );
                         }
                         else
                         {
                             writer.WriteLine( ",Error" );
                         }
                     }
                     else
                     {
                         writer.Write( ',' );
                     }
                 }
             }
             for ( int i = 0; i < numberOfModesFirstLetters; i++ )
             {
                 if ( this.RegionPercentError )
                 {
                     writer.Write( (float)( Math.Abs( aggPredToMode[i] - aggTTSToMode[i] ) / aggTTSToMode[i] ) );
                 }
                 else
                 {
                     writer.Write( aggPredToMode[i] - aggTTSToMode[i] );
                 }
                 writer.Write( ',' );
             }
             writer.WriteLine( finalError );
         }
     }
     return finalError;
 }
コード例 #6
0
ファイル: LinearSearchAI.cs プロジェクト: Cocotus/XTMF
 public float ComplexErrorFunction(ParameterSetting[] parameters, TransitLine[] transitLine, TransitLine[] predicted, float[] aggToTruth)
 {
     return this.ErrorTally.ComputeError( parameters, transitLine, predicted );
 }
コード例 #7
0
 private void InitializeAssignment()
 {
     // Get all of the initial ground truth data
     List<TransitLine> truthList = new List<TransitLine>();
     // On the first pass go through all of the data and store the records of the TTS boardings
     using ( StreamReader reader = new StreamReader( this.TruthFile ) )
     {
         string line;
         while ( ( line = reader.ReadLine() ) != null )
         {
             var split = line.Split( Comma, StringSplitOptions.RemoveEmptyEntries );
             TransitLine current = new TransitLine();
             string currentName;
             current.ID = new string[] { ( currentName = split[1] ) };
             current.Bordings = float.Parse( split[0] );
             if ( split.Length > 2 )
             {
                 current.Mode = split[2][0];
             }
             else
             {
                 current.Mode = 'b';
             }
             // Check to make sure that there isn't another ID with this name already
             int count = truthList.Count;
             for ( int j = 0; j < count; j++ )
             {
                 if ( truthList[j].ID[0] == currentName )
                 {
                     throw new XTMFRuntimeException( String.Format( "The TTS record {0} at line {1} has a duplicate entry on line {2}", currentName, j + 1, count + 1 ) );
                 }
             }
             truthList.Add( current );
         }
     }
     // now on the second pass go through and find all of the EMME Links that connect to the TTS data
     var truthEntries = truthList.Count;
     List<string>[] nameLinks = new List<string>[truthEntries];
     using ( StreamReader reader = new StreamReader( this.EMMEToTTSFile ) )
     {
         string line;
         while ( ( line = reader.ReadLine() ) != null )
         {
             var split = line.Split( Comma, StringSplitOptions.RemoveEmptyEntries );
             string ttsName = split[0];
             string emmeName = split[1];
             for ( int i = 0; i < truthEntries; i++ )
             {
                 if ( truthList[i].ID[0] == ttsName )
                 {
                     List<string> ourList;
                     if ( ( ourList = nameLinks[i] ) == null )
                     {
                         nameLinks[i] = ourList = new List<string>();
                     }
                     ourList.Add( emmeName );
                     break;
                 }
             }
         }
     }
     // Now on the third pass we go through and apply all of the EMME ID's
     for ( int i = 0; i < truthEntries; i++ )
     {
         List<string> nameList;
         if ( ( nameList = nameLinks[i] ) == null )
         {
             throw new XTMFRuntimeException( String.Format( "The TTS record {0} has no EMME Links associated with it.  Aborting.", truthList[i].ID[0] ) );
         }
         else
         {
             var temp = truthList[i];
             temp.ID = nameList.ToArray();
             truthList[i] = temp;
         }
     }
     this.Truth = truthList.ToArray();
     truthList = null;
 }