Skip to content

Commit

Permalink
Merge branch 'master' of github.com:s0sbazinga/vrptw
Browse files Browse the repository at this point in the history
  • Loading branch information
yqf-oo committed Mar 12, 2015
2 parents ab90c16 + 7e8fd20 commit f48f85c
Show file tree
Hide file tree
Showing 22 changed files with 1,782 additions and 93 deletions.
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
DDATA = ./data
DHELPERS = ./helpers
LINKOPTS = -L../lib -lEasyLocalpp
CXXFLAGS = -O2 -Wall
CXXFLAGS += -g3 -ggdb
CXX = g++
_OBJ = vrp_state_manager.o vrp_neighborhood_explorer.o \
vrp_output_manager.o vrp_tabu_list_manager.o
OBJ = $(patsubst %, $(DHELPERS)/%, $(_OBJ))
all: vrptw

vrptw: $(OBJ)
$(CXX) $(CXXFLAGS) $(LINKOPTS) -o $@ $(OBJ) \
vehicle.o client.o order.o carrier.o move.o route.o \
prob_input.o billing.o

# DATA
$(DDATA)/client.o: $(DDATA)/client.cc
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)/carrier.o: $(DDATA)/carrier.cc
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)/order.o: $(DDATA)/order.c
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)/vehicle.o: $(DDATA)/vehicle.cc
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)move.o: $(DDATA)move.cc
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)/route.o: $(DDATA)/route.cc $(DDATA)/prob_input.h
$(CXX) $(CXXFLAGS) -c $^ -I.
$(DDATA)/prob_input.o: $(DDATA)/prob_input.cc $(DDATA)/carrier.h \
$(DDATA)/vehicle.h $(DDATA)/client.h \
$(DDATA)/order.h $(DDATA)/carrier.h \
$(DHELPERS)/billing_cost_component.h \
$(CXX) $(CXXFLAGS) -c $^ -lm -I.
$(DDATA)/billing.o: $(DDATA)/billing.cc $(DHELPERS)/billing_cost_component.h
$(CXX) $(CXXFLAGS) -c $^ -lm -I.

# HELPERS
$(DHELPERS)/billing_cost_component.o: $(DHELPERS)/billing_cost_component.cc \
$(DDATA)/prob_input.h $(DDATA)/billing.h
$(CXX) $(CXXFLAGS) -c $^ -lm -I.
$(DHELPERS)/vrp_state_manager.o: $(DHELPERS)/vrp_state_manager.cc \
$(DDATA)/prob_input.h $(DDATA)/route.h \
$(DDATA)/order.h $(DDATA)/billing.h \
$(DHELPERS)/billing_cost_component.h
$(CXX) $(CXXFLAGS) $(LINKOPTS) -c $^ -I.
$(DHELPERS)/vrp_neighborhood_explorer.o: $(DHELPERS)/vrp_neighborhood_explorer.cc \
$(DHELPERS)/vrp_state_manager.h \
$(DHELPERS)/billing_cost_component.h \
$(DDATA)/route.h $(DDATA)/move.h \
$(DDATA)/prob_input.h $(DDATA)/billing.h
$(CXX) $(CXXFLAGS) $(LINKOPTS) -c $^ -I.
$(DHELPERS)/vrp_tabu_list_manager.o: $(DHELPERS)/vrp_tabu_list_manager.cc \
$(DDATA)/route.h $(DDATA)/move.h
$(CXX) $(CXXFLAGS) $(LINKOPTS) -c $^ -I.
$(DHELPERS)/vrp_output_manager.o: $(DHELPERS)/vrp_output_manager.h \
$(DDATA)/prob_input.h $(DDATA)/route.h
$(CXX) $(CXXFLAGS) $(LINKOPTS) -c $^ -I.

.PHONY: clean
clean:
@rm $(DDATA)/*.o $(DHELPERS)/*.o main
62 changes: 31 additions & 31 deletions data/billing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@

const int kBufSize = 200;

void LoadKmBilling::ReadInputData(istream &is, unsigned num_region) {
char buffer[kBufSize];
double n;
void LoadKmBilling::ReadInputData(std::istream &is, unsigned num_region) {
char buffer[kBufSize];
double n;

is >> n;
km_rate = static_cast<unsigned>(ceil(n*1000));
is >> n;
km_rate = static_cast<unsigned>(ceil(n*1000));

is >> n;
full_load_value = static_cast<unsigned>(n*100);
is >> n;
full_load_value = static_cast<unsigned>(n*100);

is.getline(buffer, kBufSize);
is.getline(buffer, kBufSize);

load_cost.resize(num_region);
load_cost.resize(num_region);

for (int i = 0; i < load_cost.size(); ++i) {
is >> n;
load_cost[i] = static_cast<unsigned>(ceil(n*1000));
for (int i = 0; i < load_cost.size(); ++i) {
is >> n;
load_cost[i] = static_cast<unsigned>(ceil(n*1000));
}

is.getline(buffer, kBufSize);
}

void VarLoadBilling::ReadInputData(istream &is, unsigned num_region) {
char buffer[kBufSize];
string s;
double n;
void VarLoadBilling::ReadInputData(std::istream &is, unsigned num_region) {
char buffer[kBufSize];
double n;
unsigned num_range;

is >> num_range;
levels.resize(num_range-1);
for (int i = 0; i < levels.size(); ++i) {
is >> level[i]; // in kg
is >> num_range;
levels.resize(num_range-1);
for (int i = 0; i < levels.size(); ++i) {
is >> levels[i]; // in kg
}
is.getline(buffer, kBufSize);

load_cost.resize(num_region);

for (int i = 0; i < num_region; ++i) {
load_cost[i].resize(num_range);
is.getline(buffer, kBufSize, ';');
s = buffer;
istringstream instr(s);
for (int j = 0; j < num_range; ++j) {
instr >> n;
load_cost[i][j] = static_cast<unsigned>(ceil(n*1000));
}
load_cost[i].resize(num_range);
is.getline(buffer, kBufSize, ';');
std::string s = buffer;
istringstream instr(s);
for (int j = 0; j < num_range; ++j) {
instr >> n;
load_cost[i][j] = static_cast<unsigned>(ceil(n*1000));
}
}
is.getline(buffer, kBufSize);
}
}

void LoadBilling::ReadInputData(istream &is, unsigned num_region) {
void LoadBilling::ReadInputData(std::istream &is, unsigned num_region) {
char buffer[kBufSize];
double n;

Expand All @@ -67,4 +67,4 @@ void VarLoadBilling::ReadInputData(istream &is, unsigned num_region) {
}

is.getline(buffer, kBufSize);
}
}
34 changes: 23 additions & 11 deletions data/billing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include "helpers/billing_cost_component.h"

// class BillingCostComponent;

class Billing {
public:
Billing(std::string i, std::string t):
id(i), type(t) { }
virtual ~Billing() { }
void SetCostComponent(BillingCostComponent* cc) {
cost_component = cc;
}
BillingCostComponent& GetCostComponent() const {
return (*cost_component);
}
// size_t CostComponents() const { return cost_component.size(); }
std::string get_id() const { return id; }
std::string get_type() const { return type; }
protected:
std::string id, type;
BillingCostComponent *cost_component;
};

// KM BILLING (cost function 1)
class KmBilling: public Billing {
public:
KmBilling(std::string i, std::string t, unsigned rate):
Billing(i, t), km_rate(rate) { }
~KmBilling() { delete cost_component; }
unsigned get_km_rate() const { return km_rate; }
private:
unsigned km_rate;
Expand All @@ -30,13 +43,14 @@ class LoadKmBilling: public Billing {
public:
LoadKmBilling(std::string i, std::string t):
Billing(i, t) { }
~LoadKmBilling() { delete cost_component; }
unsigned get_km_rate() const { return km_rate; }
unsigned get_full_load() const { return full_load_value; }
unsigned get_load_cost(unsigned r_index) const {
assert(r_index < load_cost.size());
return load_cost[r_index];
}
void ReadInputData(istream&, unsigned);
void ReadInputData(std::istream&, unsigned);
private:
unsigned km_rate;
unsigned full_load_value;
Expand All @@ -48,19 +62,16 @@ class VarLoadBilling: public Billing {
public:
VarLoadBilling(std::string i, std::string t):
Billing(i, t) { }
unsigned get_range() const { return num_range; }
unsigned get_level(unsigned i) const {
assert(i < num_range);
return levels[i];
}
~VarLoadBilling() { delete cost_component; }
unsigned get_load_cost(unsigned r_index, unsigned range) {
assert(range < num_range && r_index < load_cost.size());
assert(r_index < load_cost.size());
return load_cost[r_index][range];
}
void ReadInputData(istream&, unsigned);
unsigned operator[] (unsigned i) const { return levels[i]; }
unsigned& operator[] (unsigned i ) { return levels[i]; }
void ReadInputData(std::istream&, unsigned);
private:
unsigned num_range;
std::vector<std::vector<unsigned>> load_cost;
std::vector<std::vector<unsigned> > load_cost;
std::vector<unsigned> levels;
};

Expand All @@ -69,7 +80,8 @@ class LoadBilling: public Billing {
public:
LoadBilling(std::string i, std::string t):
Billing(i, t) { }
void ReadInputData(istream&, unsigned);
~LoadBilling() { delete cost_component; }
void ReadInputData(std::istream&, unsigned);
unsigned get_load_cost(unsigned r_index) const {
assert(r_index < load_cost.size());
return load_cost[r_index];
Expand Down
3 changes: 3 additions & 0 deletions data/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Client{
id(cid), id_region(rid), serv_time(st * 60), time_window(rt, dt) { }
std::string get_id() const { return id; }
std::string get_region() const { return id_region; }
int get_ready_time() const { return time_window.first * 60; }
int get_due_time() const { return time_window.second * 60; }
int get_service_time() const { return serv_time * 60; }
private:
std::string id, id_region;
int serv_time;
Expand Down
31 changes: 31 additions & 0 deletions data/move.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "data/move.h"

bool InsMove::operator==(const InsMove &m) const {
return (order == m.order) && (old_roue == m.old_route)
&& (old_pos == m.old_pos) && (new_route == m.new_route)
&& (new_pos == m.new_pos);
}

bool InsMove::operator!=(const InsMove &m) const {
return !(operator==(m));
}

bool InterSwap::operator==(const InterSwap &m) const {
return (ord1 == m.ord1) && (ord2 == m.ord2)
&& (route1 == m.route1) && (route2 == m.route2)
&& (pos1 == m.pos1) && (pos2 == m.pos2);
}

bool InterSwap::operator!=(const InterSwap &m) const {
return !(operator==(m));
}

bool IntraSwap::operator==(const IntraSwap &m) const {
return (ord1== m.ord1) && (ord2 == m.ord2)
&& (route1 == m.route1) && (pos1 == m.pos1)
&& (pos2 == m.pos2);
}

bool IntraSwap::operator==(const IntraSwap &m) const {
return !(operator==(m));
}
44 changes: 44 additions & 0 deletions data/move.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef _MOVE_H_
#define _MOVE_H_

class InsMove {
public:
InsMove(unsigned o, unsigned ro, unsigned po,
unsigned rn, unsigned pn):
order(o), old_route(ro), old_pos(po),
new_route(rn), new_pos(pn) { }

bool operator==(const InsMove&) const;
bool operator!=(const InsMove&) const;
unsigned order;
unsigned old_route, old_pos;
unsigned new_route, new_pos;
};

class InterSwap {
public:
InterSwap(unsigned o1, unsigned o2, unsigned r1,
unsigned r2, unsigned p1, unsigned p2):
ord1(o1), ord2(o2), route1(r1),
route2(r2), pos1(p1), pos2(p2) { }

bool operator==(const InterSwap&) const;
bool operator!=(const InterSwap&) const;
unsigned ord1, ord2;
unsigned route1, route2;
unsigned pos1, pos2;
};

class IntraSwap {
public:
IntraSwap(unsigned o1, unsigned o2, unsigned r,
unsigned p1, unsigned p2):
ord1(o1), ord2(o2), route(r), pos1(p1), pos2(p2) { }

bool operator==(const IntraSwap&) const;
bool operator!=(const IntraSwap&) const;
unsigned ord1, ord2, route;
unsigned pos1, pos2;
};

#endif
16 changes: 9 additions & 7 deletions data/order.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class Order {
{ }
Order(std::string id_o, std::string id_cli, unsigned qty, bool m,
int rd = 1, int dd = 1):
id(id_o), id_client(id_cli), quantity(q), mandatory(m),
id(id_o), id_client(id_cli), quantity(qty), mandatory(m),
date_window(rd, dd) { }
std::string get_id() const { return id; }
std::string get_client() const { return id_client; }
unsigned get_demand() const { return quantity; }
std::pair<int, int> get_dw() const { return date_window; }
bool IsMandatory() const { return mandatory; }
bool IsDayFeasible(int day) const {
return (day >= date_window.first && day <= date_window.second); }
Expand All @@ -35,19 +37,19 @@ class Order {
int group;
};

class OrderGroup : public Order{
class OrderGroup : public Order {
public:
OrderGroup(const Order &o): Order(o), members(1, o.id) { }
OrderGroup(const Order &o): Order(o), members() { members.push_back(o.get_id()); }
OrderGroup(const OrderGroup &og): Order(og), members(og.members) { }
unsigned size() const { return members.size(); }
void insert(const Order &);
bool IsGroupCompatible(const Order& o) const {
return ((o.id == id) && (o.quantity == quantity)
&& (o.date_window == date_window));
return ((o.get_client() == id_client) && (o.IsMandatory() == mandatory)
&& (o.get_dw() == date_window));
}
string& operator[](unsigned i) { return members[i]; }
std::string& operator[](unsigned i) { return members[i]; }
OrderGroup& operator=(const OrderGroup&);
private:
std::vector<string> members;
std::vector<std::string> members;
};
#endif
Loading

0 comments on commit f48f85c

Please sign in to comment.