Originally posted by: K_N_Srikanth
I have internal DATE and TIME fields in my OPL code, as well as in imported ODME data tables. They work fine, and the output tables show correct date & time values on the ILOG DOC screen.
I have a problem with writing these date and time values out to an external csv file.
1. I am using a single-row input table Parameters_DateTime, shown within the _odm.mod file as
tuple TParametersDateTime {
int referenceDate;
int dateIncrement;
int referenceTime;
int timeIncrement;
string comment;
};
TParametersDateTime parametersDateTime = .
..;
2. The relevant tuple whose info I'm trying to print to the output file is
tuple TSolutionTruckRoutes {
... (other fields)
int startDate; //mapped to DATE field in ODME input table
int startTime; //mapped to TIME field in ODME input table
int endDate; //mapped to DATE field in ODME input table
int endTime; //mapped to TIME field in ODME input table
};
{TSolutionTruckRoutes} solutionTruckRoutes;
3. External parameters OUTPUT_FILE_FOLDER and BACKSLASH are read in from a Parameters.csv input data file
string OUTPUT_FILE_FOLDER = parameter["OUTPUT_FILE_FOLDER"];
string BACKSLASH = parameter["BACKSLASH"];
4. The OPL Script executable that's presently failing is
execute WriteOutputFiles {
var wOutFilePathAndName = OUTPUT_FILE_FOLDER + BACKSLASH + "TruckRoutes.csv";
var f2=new IloOplOutputFile(wOutFilePathAndName);
f2.writeln( "//Index,","Truck,","Type,","Order,","Customer,","Product,","Tons,",
"sPlant,","ePlant,",
"sNodeType,","eNodeType,","sDate,","sTime,","eDate,","eTime,","Distance,",
"LoadMinutes,","UnloadMinutes,","WashMinutes,","TravelMinutes,","TotalMinutes,",
"sAddress,","eAddress,","Comment"
);
for(var str in solutionTruckRoutes) {
var wStartDate = new Date(parametersDateTime.referenceDate + str.startDate
//+ parametersDateTime.referenceTime + str.startTime
);
var wEndDate = new Date(parametersDateTime.referenceDate + str.endDate
//+ parametersDateTime.referenceTime + str.endTime
);
var wStartDay = wStartDate.getDate();
var wStartMonth = wStartDate.getMonth();
var wStartYear = wStartDate.getYear();
var wStartHour = wStartDate.getHours();
var wStartMinute = wStartDate.getMinutes();
var wEndDay = wEndDate.getDate();
var wEndMonth = wEndDate.getMonth();
var wEndYear = wEndDate.getYear();
var wEndHour = wEndDate.getHours();
var wEndMinute = wEndDate.getMinutes();
f2.writeln( str.index,",",
str.truckId,",",
str.truckTypeId,",",
str.orderId,",",
str.customerId,",",
str.productId,",",
str.tonsProduct,",",
str.plantStart,",",
str.plantEnd,",",
str.startNodeTypeId,",",
str.endNodeTypeId,",",
wStartDay,"-",wStartMonth,"-",wStartYear,",", //wStartDate.toLocaleString(),",",
wStartHour,":",wStartMinute,",", //str.startTime,",",
wEndDay,"-",wEndMonth,"-",wEndYear,",", //wEndDate.toLocaleString(),",",
wEndHour,":",wEndMinute,",", //str.endTime,",",
str.distance,",",
str.loadMinutes,",",
str.unloadMinutes,",",
str.washMinutes,",",
str.travelMinutes,",",
str.totalMinutes,",",
"'" + str.startFullAddress+ "'", ",",
"'" + str.endFullAddress + "'", ",",
str.comment
);
}
f2.close();
}
The problem is that all date and time values showing up in the TruckRoutes.csv file show the OPL reference date & time i.e. 31-11-1969 for date and 19:00 for time. I'm doing something stupid when trying to create the date and time values for external output, but I can't figure out what it is.
Help, please... :-)
#DecisionOptimization#OPLusingCPLEXOptimizer