Skip to content

Commit 07e238f

Browse files
authored
Update util (#35)
* update util, minor refactorings along the way
1 parent 4cd360c commit 07e238f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+135
-66
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ find_package(LibZip)
2828

2929
# set compiler flags, see http://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
3030
if(OPENMP_FOUND)
31-
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} -O3 -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wno-keyword-macro -Wformat-security -Wformat=2")
31+
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} -O3 -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2")
3232

3333
else()
3434
message(STATUS "Configuring without OpenMP")
35-
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wno-keyword-macro -Wformat-security -Wformat=2")
35+
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2")
3636
endif()
3737

3838
if(GUROBI_FOUND)

src/gtfs2graph/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ add_executable(gtfs2graph ${gtfs2graph_main})
1616
add_library(gtfs2graph_dep ${gtfs2graph_SRC})
1717

1818
target_include_directories(gtfs2graph_dep PUBLIC ${PROJECT_SOURCE_DIR}/src/cppgtfs/src)
19-
target_link_libraries(gtfs2graph gtfs2graph_dep util ad_cppgtfs -lpthread)
19+
target_link_libraries(gtfs2graph gtfs2graph_dep pb_util_geo pb_util_graph pb_util_json ad_cppgtfs -lpthread)

src/gtfs2graph/Gtfs2GraphMain.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
#include "util/log/Log.h"
2121

2222
using namespace gtfs2graph;
23-
using std::string;
23+
using util::ERROR;
24+
using util::DEBUG;
2425

2526
// _____________________________________________________________________________
2627
int main(int argc, char** argv) {
27-
// disable output buffering for standard output
28-
setbuf(stdout, NULL);
29-
3028
// initialize randomness
3129
srand(time(NULL) + rand());
3230

src/gtfs2graph/builder/Builder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ using ad::cppgtfs::gtfs::Stop;
3232
using ad::cppgtfs::gtfs::StopTime;
3333
using ad::cppgtfs::gtfs::Trip;
3434

35+
using util::DEBUG;
36+
3537
// _____________________________________________________________________________
3638
Builder::Builder(const config::Config* cfg) : _cfg(cfg) {}
3739

src/loom/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ configure_file (
2222
add_executable(loom ${loom_main})
2323
add_library(loom_dep ${loom_SRC})
2424

25-
target_link_libraries(loom loom_dep shared_dep dot_dep util ${GLPK_LIBRARY} ${GUROBI_LIBRARY} ${COIN_LIBRARIES} -lpthread)
25+
target_link_libraries(loom loom_dep shared_dep dot_dep pb_util_graph pb_util pb_util_json pb_util_geo ${GLPK_LIBRARY} ${GUROBI_LIBRARY} ${COIN_LIBRARIES} -lpthread)

src/loom/LoomMain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "util/log/Log.h"
2222

2323
using namespace loom;
24+
using util::DEBUG;
25+
using util::ERROR;
2426

2527
// _____________________________________________________________________________
2628
int main(int argc, char** argv) {

src/loom/optim/CombNoILPOptimizer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818

1919
using loom::optim::CombNoILPOptimizer;
2020
using shared::rendergraph::HierarOrderCfg;
21+
using util::DEBUG;
2122

2223
// _____________________________________________________________________________
23-
double CombNoILPOptimizer::optimizeComp(OptGraph* og, const std::set<OptNode*>& g,
24-
HierarOrderCfg* hc, size_t depth,
25-
OptResStats& stats) const {
24+
double CombNoILPOptimizer::optimizeComp(OptGraph* og,
25+
const std::set<OptNode*>& g,
26+
HierarOrderCfg* hc, size_t depth,
27+
OptResStats& stats) const {
2628
size_t maxC = maxCard(g);
2729
double solSp = solutionSpaceSize(g);
2830

2931
LOGTO(DEBUG, std::cerr) << prefix(depth)
30-
<< "(CombNoILPOptimizer) Optimizing comp with " << g.size()
31-
<< " nodes, max card " << maxC << ", sol space size "
32-
<< solSp;
32+
<< "(CombNoILPOptimizer) Optimizing comp with "
33+
<< g.size() << " nodes, max card " << maxC
34+
<< ", sol space size " << solSp;
3335

3436
if (maxC == 1) {
3537
return _nullOpt.optimizeComp(og, g, hc, depth + 1, stats);

src/loom/optim/CombOptimizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using loom::optim::CombOptimizer;
2020
using shared::rendergraph::HierarOrderCfg;
21+
using util::DEBUG;
2122

2223
// _____________________________________________________________________________
2324
double CombOptimizer::optimizeComp(OptGraph* og, const std::set<OptNode*>& g,

src/loom/optim/ExhaustiveOptimizer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
44

55
#include <algorithm>
6+
#include <random>
7+
#include <chrono>
68
#include <unordered_map>
9+
710
#include "loom/optim/ExhaustiveOptimizer.h"
811
#include "shared/linegraph/Line.h"
912
#include "util/log/Log.h"
@@ -14,6 +17,8 @@ using loom::optim::ExhaustiveOptimizer;
1417
using shared::linegraph::Line;
1518
using shared::rendergraph::HierarOrderCfg;
1619

20+
using util::DEBUG;
21+
1722
// _____________________________________________________________________________
1823
double ExhaustiveOptimizer::optimizeComp(OptGraph* og,
1924
const std::set<OptNode*>& g,
@@ -127,6 +132,9 @@ void ExhaustiveOptimizer::initialConfig(const std::set<OptNode*>& g,
127132
// _____________________________________________________________________________
128133
void ExhaustiveOptimizer::initialConfig(const std::set<OptNode*>& g,
129134
OptOrderCfg* cfg, bool sorted) const {
135+
auto seed = std::chrono::system_clock::now().time_since_epoch().count();
136+
auto randEng = std::default_random_engine(seed);
137+
130138
for (OptNode* n : g) {
131139
for (OptEdge* e : n->getAdjList()) {
132140
if (e->getFrom() != n) continue;
@@ -140,7 +148,7 @@ void ExhaustiveOptimizer::initialConfig(const std::set<OptNode*>& g,
140148
if (sorted) {
141149
std::sort((*cfg)[e].begin(), (*cfg)[e].end());
142150
} else {
143-
std::random_shuffle((*cfg)[e].begin(), (*cfg)[e].end());
151+
std::shuffle((*cfg)[e].begin(), (*cfg)[e].end(), randEng);
144152
}
145153
}
146154
}

src/loom/optim/GreedyOptimizer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <algorithm>
66
#include <unordered_map>
7+
78
#include "loom/optim/GreedyOptimizer.h"
89
#include "shared/linegraph/Line.h"
910
#include "util/log/Log.h"
@@ -14,11 +15,12 @@ using loom::optim::GreedyOptimizer;
1415
using loom::optim::SettledEdgs;
1516
using shared::linegraph::Line;
1617
using shared::rendergraph::HierarOrderCfg;
18+
using util::DEBUG;
1719

1820
// _____________________________________________________________________________
1921
double GreedyOptimizer::optimizeComp(OptGraph* og, const std::set<OptNode*>& g,
20-
HierarOrderCfg* hc, size_t depth,
21-
OptResStats& stats) const {
22+
HierarOrderCfg* hc, size_t depth,
23+
OptResStats& stats) const {
2224
UNUSED(og);
2325
UNUSED(stats);
2426
LOGTO(DEBUG, std::cerr) << prefix(depth)
@@ -36,7 +38,7 @@ double GreedyOptimizer::optimizeComp(OptGraph* og, const std::set<OptNode*>& g,
3638

3739
// _____________________________________________________________________________
3840
void GreedyOptimizer::getFlatConfig(const std::set<OptNode*>& g,
39-
OptOrderCfg* cfg) const {
41+
OptOrderCfg* cfg) const {
4042
const OptEdge* e = 0;
4143
SettledEdgs settled;
4244

0 commit comments

Comments
 (0)