-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
157 lines (116 loc) · 4.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
BDIR = bin
IDIR = include
LDIR = lib
ODIR = obj
SDIR = src
TDIR = test
QSOPT_DIR ?= /usr/local/lib/qsopt
CPLEX_DIR ?= /usr/local/lib/cplex
CAIRO_INCLUDES = $(shell pkg-config --cflags cairomm-1.0)
INCLUDE += -I$(SDIR) -I$(IDIR) $(CAIRO_INCLUDES)
OBJECT_INCLUDES = $(IDIR)/concorde.h
CAIRO_LIBS = $(shell pkg-config --libs cairomm-1.0)
TARGET_LIBS = $(LDIR)/concorde.a
LIBS = $(CPLEX_DIR)/libcplex.a $(QSOPT_DIR)/qsopt.a $(CAIRO_LIBS)
CXX=mpic++
CXXFLAGS=-Wall -Wextra -Weffc++ -ggdb -std=c++11 -pthread
COMPILE_OBJ = $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
MKDIR = if [ ! -d "$(shell dirname $@)" ]; then mkdir -p $(shell dirname $@); fi
SRCS = $(SDIR)/graph/graph.cc \
$(SDIR)/graphics/image_generator.cc \
$(SDIR)/simulate/multi_node_replacement.cc \
$(SDIR)/simulate/single_node_replacement.cc \
$(SDIR)/simulate/tsp_simulator.cc \
$(SDIR)/simulate/two_node_replacement.cc \
$(SDIR)/solve/bellman_held_karp.cc \
$(SDIR)/solve/brute_force_search.cc \
$(SDIR)/solve/concorde_solver.cc \
$(SDIR)/solve/linkern_approximation.cc \
$(SDIR)/solve/nearest_neighbor_search.cc \
$(SDIR)/solve/parallel_concorde_solver.cc \
$(SDIR)/solve/tsp_algorithm.cc \
$(SDIR)/solve/tsp_algorithm_factory.cc \
$(SDIR)/solve/tsp_solver.cc \
$(SDIR)/tsplib/tsp.cc \
$(SDIR)/tsplib/edge_weight_type.cc \
$(SDIR)/tsplib/coord/ceil_euclidean_distance.cc \
$(SDIR)/tsplib/coord/coord.cc \
$(SDIR)/tsplib/coord/distance_calc.cc \
$(SDIR)/tsplib/coord/distance_calc_factory.cc \
$(SDIR)/tsplib/coord/euclidean_distance.cc \
$(SDIR)/tsplib/coord/geo_distance.cc \
$(SDIR)/tsplib/coord/manhattan_distance.cc \
$(SDIR)/tsplib/coord/max_distance.cc \
$(SDIR)/tsplib/coord/pseudo_euclidean_distance.cc \
$(SDIR)/util/io_util.cc
OBJS = $(patsubst $(SDIR)%.cc, $(ODIR)%.o, $(SRCS))
all: $(BDIR)/parse_tsp $(BDIR)/solve_tsp $(BDIR)/generate_tsp $(BDIR)/single_city_simulation $(BDIR)/two_city_simulation $(BDIR)/mpi_wrapper
tests: $(BDIR)/tsp_distance_calc_test $(BDIR)/tsp_bf_test $(BDIR)/tsp_bhk_test $(BDIR)/tsp_concorde_test
test: tests
$(BDIR)/tsp_distance_calc_test
$(BDIR)/tsp_bf_test
$(BDIR)/tsp_bhk_test
$(BDIR)/tsp_concorde_test
## Distributed Executables
$(BDIR)/parse_tsp: $(OBJS) $(SDIR)/parse_tsp.cc $(TARGET_LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ $(LIBS) -o $@
$(BDIR)/solve_tsp: $(OBJS) $(SDIR)/solve_tsp.cc $(TARGET_LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ $(LIBS) -o $@
$(BDIR)/generate_tsp: $(OBJS) $(SDIR)/generate_tsp.cc $(TARGET_LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ $(LIBS) -o $@
$(BDIR)/single_city_simulation: $(OBJS) $(SDIR)/single_city_simulation.cc $(TARGET_LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ $(LIBS) -o $@
$(BDIR)/two_city_simulation: $(OBJS) $(SDIR)/two_city_simulation.cc $(TARGET_LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ $(LIBS) -o $@
###
$(BDIR)/mpi_wrapper: $(SDIR)/mpi_wrapper.cc
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@
## Unit Tests
$(ODIR)/$(TDIR)/tsp_solution_test.o: $(TDIR)/tsp_solution_test.cc
$(MKDIR)
$(COMPILE_OBJ)
$(BDIR)/tsp_distance_calc_test: $(OBJS) $(TDIR)/tsp_distance_calc_test.cc lib/gtest_main.a $(LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) -lpthread $^ -o $@
$(BDIR)/tsp_bf_test: $(OBJS) $(ODIR)/$(TDIR)/tsp_solution_test.o $(TDIR)/tsp_bf_test.cc lib/gtest_main.a $(LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) -lpthread $^ -o $@
$(BDIR)/tsp_bhk_test: $(OBJS) $(ODIR)/$(TDIR)/tsp_solution_test.o $(TDIR)/tsp_bhk_test.cc lib/gtest_main.a $(LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) -lpthread $^ -o $@
$(BDIR)/tsp_concorde_test: $(OBJS) $(ODIR)/$(TDIR)/tsp_solution_test.o $(TDIR)/tsp_concorde_test.cc lib/gtest_main.a $(LIBS)
$(CXX) $(CXXFLAGS) $(INCLUDE) -lpthread $^ -o $@
###
## GTest
GTEST_DIR ?= /usr/src/gtest
CPPFLAGS += -isystem $(GTEST_DIR)/include
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h $(GTEST_DIR)/include/gtest/internal/*.h
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h
$(ODIR)/gtest-all.o: $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc -o $@
$(ODIR)/gtest_main.o: $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest_main.cc -o $@
$(LDIR)/gtest.a: $(ODIR)/gtest-all.o
$(AR) $(ARFLAGS) $@ $^
$(LDIR)/gtest_main.a: $(ODIR)/gtest-all.o $(ODIR)/gtest_main.o
$(AR) $(ARFLAGS) $@ $^
###
## Concorde
CONCORDE_DIR ?= /usr/local/src/concorde
MAKE_CONCORDE = \
(cd $(CONCORDE_DIR) && $(MAKE) clean && ./configure --with-qsopt=$(QSOPT_DIR)) && \
$(MAKE) -C $(CONCORDE_DIR)
$(CONCORDE_DIR)/concorde.a:
$(MAKE_CONCORDE)
$(CONCORDE_DIR)/concorde.h:
$(MAKE_CONCORDE)
$(LDIR)/concorde.a: $(CONCORDE_DIR)/concorde.a
cp $^ $@
$(IDIR)/concorde.h: $(CONCORDE_DIR)/concorde.h
cp $^ $@
sed -i 's/new/new_/g' $@
sed -i 's/class/class_/g' $@
###
$(ODIR)/%.o: $(SDIR)/%.cc $(OBJECT_INCLUDES)
$(MKDIR)
$(COMPILE_OBJ)
clean:
rm -Rf $(BDIR)/* $(ODIR)/* $(LDIR)/* $(IDIR)/* $(CONCORDE_DIR)/concorde.a \
$(CONCORDE_DIR)/concorde.h