00001
00002
00004
00005 #include "stdafx.h"
00006 #include "EvolveTraffic.h"
00007 #include "ConfigData.h"
00008
00009 #ifdef _DEBUG
00010 #undef THIS_FILE
00011 static char THIS_FILE[]=__FILE__;
00012 #define new DEBUG_NEW
00013 #endif
00014
00016
00018
00019 CConfigData::CConfigData()
00020 {
00021 m_CommentString = "//";
00022 SetDefaults();
00023 }
00024
00025 CConfigData::~CConfigData()
00026 {
00027
00028 }
00029
00030
00031
00032 CConfigData g_ConfigData;
00033
00034 bool CConfigData::ReadData(std::string inFile)
00035 {
00036 if( m_CSV.OpenFile(inFile, ",") )
00037 {
00038 ExtractData();
00039 return true;
00040 }
00041 return false;
00042 }
00043
00044 void CConfigData::ExtractData()
00045 {
00046 string str;
00047
00048 str = GetNextDataLine(); IDM.LANECHANGE_MIN_GAP = stringToDouble(str);
00049 str = GetNextDataLine(); IDM.MIN_SPACE_FOR_NEXT_VEHICLE = stringToDouble(str);
00050 str = GetNextDataLine(); IDM.SAFE_BRAKING = stringToDouble(str);
00051 str = GetNextDataLine(); IDM.T_DELAY = stringToDouble(str);
00052
00053 str = GetNextDataLine(); Road.ROAD_END_BUFFER = stringToInt(str);
00054 str = GetNextDataLine(); Road.RoadFeatures.SpeedLimit.SPEEDLIMIT_MIN = stringToInt(str);
00055 str = GetNextDataLine(); Road.RoadFeatures.SpeedLimit.SPEEDLIMIT_MAX = stringToInt(str);
00056 str = GetNextDataLine(); Road.RoadFeatures.Gradient.MAX_SLOPE = stringToInt(str);
00057 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.A_FLAG = stringToBool(str);
00058 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.A_MIN = stringToDouble(str);
00059 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.B_FLAG = stringToBool(str);
00060 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.T_SLOPE = stringToDouble(str);
00061 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.V0_MIN = stringToDouble(str);
00062 str = GetNextDataLine(); Road.RoadFeatures.Gradient.IDM_Modifiers.V0_SLOPE = stringToDouble(str);
00063
00064 str = GetNextDataLine(); Time.DAYS_PER_MT = stringToInt(str);
00065 str = GetNextDataLine(); Time.MTS_PER_YR = stringToInt(str);
00066
00067 str = GetNextDataLine(); VehicleID.CRANE_AVERAGE_SPACING = stringToDouble(str);
00068 str = GetNextDataLine(); VehicleID.CRANE_MAX_SPACING = stringToDouble(str);
00069 str = GetNextDataLine(); VehicleID.LOWLOADER_MIN_MAX_SPACING = stringToDouble(str);
00070 str = GetNextDataLine(); VehicleID.SMALL_TRUCK_NO_AXLES = stringToInt(str);
00071 str = GetNextDataLine(); VehicleID.TRUCK_WEIGHT_THRESHOLD = stringToInt(str);
00072
00073 str = GetNextDataLine(); View.MIN_VIEW_SCALE = stringToDouble(str);
00074 str = GetNextDataLine(); View.DATATIP_DELAY = stringToDouble(str);
00075 str = GetNextDataLine(); View.Colours.Vehicles.VEH_COLOR_CAR = stringToColour(str);
00076 str = GetNextDataLine(); View.Colours.Vehicles.VEH_COLOR_SMALLTRUCK = stringToColour(str);
00077 str = GetNextDataLine(); View.Colours.Vehicles.VEH_COLOR_LARGETRUCK = stringToColour(str);
00078 str = GetNextDataLine(); View.Colours.Vehicles.VEH_COLOR_CRANE = stringToColour(str);
00079 str = GetNextDataLine(); View.Colours.Vehicles.VEH_COLOR_LOWLOADER = stringToColour(str);
00080 str = GetNextDataLine(); View.Colours.DrawElements.CLR_BACKGRND = stringToColour(str);
00081 str = GetNextDataLine(); View.Colours.DrawElements.CLR_ROAD_SURFACE = stringToColour(str);
00082 str = GetNextDataLine(); View.Colours.DrawElements.CLR_ROAD_LINES = stringToColour(str);
00083 str = GetNextDataLine(); View.Colours.DrawElements.CLR_RULER_LINES = stringToColour(str);
00084 str = GetNextDataLine(); View.Colours.DrawElements.CLR_RULER_TEXT = stringToColour(str);
00085 str = GetNextDataLine(); View.Colours.DrawElements.CLR_LEGEND_TEXT = stringToColour(str);
00086 str = GetNextDataLine(); View.Colours.DrawElements.CLR_DET_OUTPUT = stringToColour(str);
00087 str = GetNextDataLine(); View.Colours.DrawElements.CLR_DET_FLOWDENSITY = stringToColour(str);
00088 str = GetNextDataLine(); View.Colours.DrawElements.CLR_DET_HEADWAY = stringToColour(str);
00089 str = GetNextDataLine(); View.Colours.DrawElements.CLR_DET_COMPOSITION = stringToColour(str);
00090 str = GetNextDataLine(); View.Colours.DrawElements.CLR_FEAT_SPEEDLIMIT = stringToColour(str);
00091 str = GetNextDataLine(); View.Colours.DrawElements.CLR_FEAT_GRADIENT = stringToColour(str);
00092
00093 m_CSV.CloseFile();
00094 }
00095
00096 string CConfigData::GetNextDataLine()
00097 {
00098 string line;
00099 m_CSV.getline(line);
00100 while(line.substr(0,2) == m_CommentString)
00101 m_CSV.getline(line);
00102
00103 return line;
00104 }
00105
00106
00107
00108 void CConfigData::SetDefaults()
00109 {
00110 IDM.LANECHANGE_MIN_GAP = 2.0;
00111 IDM.MIN_SPACE_FOR_NEXT_VEHICLE = 27.0;
00112 IDM.SAFE_BRAKING = -12.0;
00113 IDM.T_DELAY = 1.6;
00114
00115
00116 Road.ROAD_END_BUFFER = 1000;
00117
00118 Road.RoadFeatures.MAX_NO_ROAD_FEATURES = 10;
00119
00120 Road.RoadFeatures.SpeedLimit.SPEEDLIMIT_MIN = 10;
00121 Road.RoadFeatures.SpeedLimit.SPEEDLIMIT_MAX = 200;
00122
00123 Road.RoadFeatures.Gradient.MAX_SLOPE = 15;
00124 Road.RoadFeatures.Gradient.IDM_Modifiers.A_FLAG = true;
00125 Road.RoadFeatures.Gradient.IDM_Modifiers.A_MIN = 0.1;
00126 Road.RoadFeatures.Gradient.IDM_Modifiers.B_FLAG = true;
00127 Road.RoadFeatures.Gradient.IDM_Modifiers.T_SLOPE = 10.0;
00128 Road.RoadFeatures.Gradient.IDM_Modifiers.V0_MIN = 0.1;
00129 Road.RoadFeatures.Gradient.IDM_Modifiers.V0_SLOPE = 0.2;
00130
00131
00132 Time.DAYS_PER_MT = 25;
00133 Time.MTS_PER_YR = 10;
00134
00135
00136 VehicleID.CRANE_AVERAGE_SPACING = 2.5;
00137 VehicleID.CRANE_MAX_SPACING = 4.5;
00138 VehicleID.LOWLOADER_MIN_MAX_SPACING = 7.5;
00139 VehicleID.SMALL_TRUCK_NO_AXLES = 3;
00140 VehicleID.TRUCK_WEIGHT_THRESHOLD = 35;
00141
00142
00143 View.MIN_VIEW_SCALE = 0.1;
00144 View.DATATIP_DELAY = 20.0;
00145
00146 View.Colours.Vehicles.VEH_COLOR_CAR = RGB(0,0,0);
00147 View.Colours.Vehicles.VEH_COLOR_SMALLTRUCK = RGB(0,0,255);
00148 View.Colours.Vehicles.VEH_COLOR_LARGETRUCK = RGB(255,0,0);
00149 View.Colours.Vehicles.VEH_COLOR_CRANE = RGB(0,255,0);
00150 View.Colours.Vehicles.VEH_COLOR_LOWLOADER = RGB(100,100,100);
00151
00152 View.Colours.DrawElements.CLR_BACKGRND = RGB(255,255,255);
00153 View.Colours.DrawElements.CLR_ROAD_SURFACE = RGB(200,200,200);
00154 View.Colours.DrawElements.CLR_ROAD_LINES = RGB(0,0,0);
00155 View.Colours.DrawElements.CLR_RULER_LINES = RGB(0,0,0);
00156 View.Colours.DrawElements.CLR_RULER_TEXT = RGB(0,0,0);
00157 View.Colours.DrawElements.CLR_LEGEND_TEXT = RGB(0,0,0);
00158 View.Colours.DrawElements.CLR_DET_OUTPUT = RGB(255,255,0);
00159 View.Colours.DrawElements.CLR_DET_FLOWDENSITY = RGB(0,255,0);
00160 View.Colours.DrawElements.CLR_DET_HEADWAY = RGB(0,0,255);
00161 View.Colours.DrawElements.CLR_DET_COMPOSITION = RGB(0,0,0);
00162 View.Colours.DrawElements.CLR_FEAT_SPEEDLIMIT = RGB(255,0,0);
00163 View.Colours.DrawElements.CLR_FEAT_GRADIENT = RGB(0,255,0);
00164 }
00165
00166 double CConfigData::stringToDouble(string line)
00167 {
00168 double val; char data[15];
00169 line.copy(data, 14, 0);
00170 val = atof(data);
00171 return val;
00172 }
00173
00174 int CConfigData::stringToInt(string line)
00175 {
00176 int val = 0; char data[15];
00177 line.copy(data, 14, 0);
00178 val = atoi(data);
00179 return val;
00180 }
00181
00182 bool CConfigData::stringToBool(string line)
00183 {
00184 int val = stringToInt(line);
00185 if(val == 1)
00186 return true;
00187 else
00188 return false;
00189 }
00190
00191
00192 COLORREF CConfigData::stringToColour(string line)
00193 {
00194 int red, green, blue;
00195 string str;
00196
00197 str = m_CSV.getfield(0); red = stringToInt(str);
00198 str = m_CSV.getfield(1); green = stringToInt(str);
00199 str = m_CSV.getfield(2); blue = stringToInt(str);
00200
00201 return RGB(red,green,blue);
00202 }
00203
00204