Skip to content

Commit

Permalink
Merge pull request #8 from jdlph/main
Browse files Browse the repository at this point in the history
Restructure the directories and cosmetic updates on README
  • Loading branch information
asu-trans-ai-lab authored Mar 20, 2021
2 parents 6d9244a + d8c5237 commit 9cf3cd9
Show file tree
Hide file tree
Showing 56 changed files with 163 additions and 314 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ test_dll/link_performance.csv
test_dll/agent.csv
test_dll/solution.csv
test_dll/log.txt
test_dll/log.csv
# untrack build folder for building shared libraries
build/
build/
.DS_Store
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ elseif(UNIX)
message("Building so or dylib file on ${CMAKE_SYSTEM_NAME}")
endif()

# specify the C++ standard
# C++11 is necessary as teestream.h requires C++11 to be complied
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# enable OpenMP
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "-Xpreprocessor -fopenmp -lomp")
Expand All @@ -21,7 +26,7 @@ endif()
set(CMAKE_BUILD_TYPE "Release")
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

add_library(DTALite_DLL SHARED MathLibrary.cpp main_api.cpp)
add_library(DTALite_DLL SHARED main_api.cpp)

# using OpenMP, the second command is only needed for macOS
find_package(OpenMP REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions src/v2/DLL_src/DP/DP.vcxproj → DTALite/v2/dll/DP/DP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@
<ClInclude Include="framework.h" />
<ClInclude Include="MathLibrary.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="teestream.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="MathLibrary.cpp" />
<ClCompile Include="main_api.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
Expand Down
109 changes: 13 additions & 96 deletions src/v2/DLL_src/DP/FlashDTA.cpp → DTALite/v2/dll/DP/FlashDTA.cpp
Original file line number Diff line number Diff line change
@@ -1,93 +1,19 @@
// Portions Copyright 2019
// Xuesong Zhou
// If you help write or modify the code, please also list your names here.
// The reason of having Copyright info here is to ensure all the modified version, as a whole, under the GPL
// and further prevent a violation of the GPL.

// More about "How to use GNU licenses for your own software"
// http://www.gnu.org/licenses/gpl-howto.html

#include "stdafx.h"

// beginning of log file
//a class that simultaneously outputs to ostream and ofstream objects
//// http://www.cplusplus.com/forum/general/64174/#msg347154
/* Portions Copyright 2019 Xuesong Zhou
*
* If you help write or modify the code, please also list your names here.
* The reason of having Copyright info here is to ensure all the modified version, as a whole, under the GPL
* and further prevent a violation of the GPL.
*
* More about "How to use GNU licenses for your own software"
* http://www.gnu.org/licenses/gpl-howto.html
*/

#include "pch.h"
#include <iostream>

template < typename C, typename T = std::char_traits<C> >

struct basic_teebuf : public std::basic_streambuf<C, T>
{
typedef std::basic_streambuf<C, T> streambuf_type;
typedef typename T::int_type int_type;

basic_teebuf(streambuf_type* buff_a, streambuf_type* buff_b)
: first(buff_a), second(buff_b) {}

protected:
virtual int_type overflow(int_type c)
{
const int_type eof = T::eof();
if (T::eq_int_type(c, eof)) return T::not_eof(c);
else
{
const C ch = T::to_char_type(c);
if (T::eq_int_type(first->sputc(ch), eof) ||
T::eq_int_type(second->sputc(ch), eof))
return eof;
else return c;
}
}

virtual int sync()
{
return !first->pubsync() && !second->pubsync() ? 0 : -1;
}

private:
streambuf_type* first;
streambuf_type* second;
};

template < typename C, typename T = std::char_traits<C> >
struct basic_teestream : public std::basic_ostream<C, T>
{
// add more controls of the debug logs
//
int debug_level;
int log_sig;
int log_odme;
int log_path;
int log_dta;
int log_ue;


typedef std::basic_ostream<C, T> stream_type;
typedef basic_teebuf<C, T> streambuff_type;

basic_teestream(stream_type& first, stream_type& second)
: stream_type(&stmbuf), stmbuf(first.rdbuf(), second.rdbuf()) {}

basic_teestream(streambuff_type* first, streambuff_type* second)
: stream_type(&stmbuf), stmbuf(first, second) {}

~basic_teestream() { stmbuf.pubsync(); }

private: streambuff_type stmbuf;
};

typedef basic_teebuf<char> teebuf;
typedef basic_teestream<char> teestream;

#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>

// end of log file
#include "teestream.h"

extern teestream log_out;
extern double SignalAPI(int iteration_number, int MainSigModual_mode, int signal_updating_output);
#include "main_api.cpp";
#include "signal_api.cpp";

Expand All @@ -96,7 +22,6 @@ teestream log_out(std::cout, file);

int main(int argc, TCHAR* argv[], TCHAR* envp[])
{

// reset all the log files to defult 0: not output; if want to output these logs set to 1
log_out << "STALite Log" << std::fixed << std::setw(12) << '\n';
log_out.debug_level = 0;
Expand All @@ -114,8 +39,6 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
bool flag_default = false;
int default_volume = 1;



CCSVParser parser_settings;
parser_settings.IsFirstLineHeader = false;

Expand All @@ -125,7 +48,6 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
{
if (parser_settings.SectionName == "[assignment]")
{

int value_int;
string assignment_mode_str;
parser_settings.GetValueByFieldName("number_of_iterations", iteration_number, true, true);
Expand Down Expand Up @@ -159,14 +81,11 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
// the start interation of generating signals, if there is no signals set this number larger than the iteration number
parser_settings.GetValueByFieldName("signal_updating_iterations", signal_updating_iterations, true, false);


break; // just one record
}

if (parser_settings.SectionName == "[log]")
{


parser_settings.GetValueByFieldName("sig", log_out.log_sig,false);
parser_settings.GetValueByFieldName("odme", log_out.log_odme, false);
parser_settings.GetValueByFieldName("path", log_out.log_path, false);
Expand All @@ -184,7 +103,5 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
return 0;
}


network_assignment(iteration_number, assignment_mode, column_updating_iterations, signal_updating_iterations); // obtain initial flow values

network_assignment(iteration_number, assignment_mode, column_updating_iterations); // obtain initial flow values
}
11 changes: 11 additions & 0 deletions DTALite/v2/dll/DP/MathLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GUARD_MATHLIBRARY_H

#ifdef _WIN32
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API
#endif

extern "C" MATHLIBRARY_API double network_assignment(int assignment_mode, int iteration_number, int column_updating_iterations);

#endif
File renamed without changes.
61 changes: 29 additions & 32 deletions src/v2/DLL_src/DP/main_api.cpp → DTALite/v2/dll/DP/main_api.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

// Portions Copyright 2019
// Xuesong (Simon) Zhou
// If you help write or modify the code, please also list your names here.
// The reason of having Copyright info here is to ensure all the modified version, as a whole, under the GPL
// and further prevent a violation of the GPL.

// More about "How to use GNU licenses for your own software"
// http://www.gnu.org/licenses/gpl-howto.html

#pragma warning( disable : 4305 4267 4018)
/* Portions Copyright 2019 Xuesong Zhou
*
* If you help write or modify the code, please also list your names here.
* The reason of having Copyright info here is to ensure all the modified version, as a whole, under the GPL
* and further prevent a violation of the GPL.
*
* More about "How to use GNU licenses for your own software"
* http://www.gnu.org/licenses/gpl-howto.html
*/

//#include "pch.h"

#pragma warning(disable: 4305 4267 4018)
#pragma warning(disable: 4244) // stop warning: "conversion from 'int' to 'float', possible loss of data"
#include <iostream>
#include <fstream>
#include <list>
Expand All @@ -24,8 +27,10 @@
#include <map>
#include <sstream>
#include <iomanip>
#include "MathLibrary.h"
#include <cstring>
#include "MathLibrary.h"
#include "teestream.h"

using namespace std;
using std::string;
using std::ifstream;
Expand Down Expand Up @@ -58,19 +63,16 @@ using std::max;

/* number_of_seconds_per_interval should satisify the ratio of 60/number_of_seconds_per_interval is an integer*/



// Linear congruential generator
#define LCG_a 17364
#define LCG_c 0
#define LCG_M 65521 // it should be 2^32, but we use a small 16-bit number to save memory



#define sprintf_s sprintf

FILE* g_pFileOutputLog = NULL;
ofstream g_fout("log.txt");
//teestream g_fout(std::cout, file);

int g_debug_level = 0;
int g_log_odme = 0;
int g_log_path = 0;
Expand All @@ -82,16 +84,11 @@ void fopen_ss(FILE **file, const char *fileName, const char *mode)
*file = fopen(fileName, mode);
}


void g_ProgramStop();


//below shows where the functions used in Agentlite.cpp come from!
//Utility.cpp

#pragma warning(disable: 4244) // stop warning: "conversion from 'int' to 'float', possible loss of data"


class CCSVParser
{
public:
Expand Down Expand Up @@ -3558,7 +3555,7 @@ void g_ReadInputData(Assignment& assignment)
float value = g_zone_vector[o].obs_production * g_zone_vector[d].obs_attraction / max(0.0001f, total_attraction);
fprintf(g_pFileODMatrix, "%d,%d,%.4f,\n", g_zone_vector[o].zone_id, g_zone_vector[d].zone_id, value);

g_fout << "o= " << g_zone_vector[o].zone_id << " d= " << g_zone_vector[d].zone_id << ":" << value << endl;
// g_fout << "o= " << g_zone_vector[o].zone_id << " d= " << g_zone_vector[d].zone_id << ":" << value << endl;
}

}
Expand Down Expand Up @@ -3724,23 +3721,23 @@ void g_ReadInputData(Assignment& assignment)


int demand_period_id = assignment.g_DemandPeriodVector[tau].demand_period_id;
sprintf_s (VDF_field_name, "VDF_fftt%d", demand_period_id);
sprintf (VDF_field_name, "VDF_fftt%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].FFTT,false,false); // FFTT should be per min

sprintf_s (VDF_field_name, "VDF_cap%d", demand_period_id);
sprintf (VDF_field_name, "VDF_cap%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].capacity, false, false); // capacity should be per period per link (include all lanes)

sprintf_s (VDF_field_name, "VDF_alpha%d", demand_period_id);
sprintf (VDF_field_name, "VDF_alpha%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].alpha, false, false);

sprintf_s (VDF_field_name, "VDF_beta%d", demand_period_id);
sprintf (VDF_field_name, "VDF_beta%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].beta, false, false);

sprintf_s(VDF_field_name, "VDF_PHF%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].PHF);
sprintf(VDF_field_name, "VDF_PHF%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].PHF, false, false);

sprintf_s (VDF_field_name, "VDF_mu%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].mu); // mu should be per hour per link, so that we can calculate congestion duration and D/mu in BPR-X
sprintf (VDF_field_name, "VDF_mu%d", demand_period_id);
parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].mu, false, false); // mu should be per hour per link, so that we can calculate congestion duration and D/mu in BPR-X

//sprintf_s (VDF_field_name, "VDF_gamma%d", demand_period_id); // remove gamma
//parser_link.GetValueByFieldName(VDF_field_name, link.VDF_period[tau].gamma);
Expand Down Expand Up @@ -5734,7 +5731,7 @@ void CLink::CalculateTD_VDFunction()
}


double network_assignment(int iteration_number, int assignment_mode, int column_updating_iterations)
double network_assignment(int assignment_mode, int iteration_number, int column_updating_iterations)
{
// for testing
cout << "network assignment" << endl;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9cf3cd9

Please sign in to comment.