Skip to content

Commit

Permalink
Neighborhood Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
yqf-oo committed Mar 1, 2015
1 parent 2ee3086 commit e1a2fd3
Show file tree
Hide file tree
Showing 11 changed files with 935 additions and 19 deletions.
1 change: 1 addition & 0 deletions data/billing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <string>
#include <vector>
#include <cassert>

class BillingCostComponent;

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
10 changes: 6 additions & 4 deletions data/prob_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <cassert>
Expand Down Expand Up @@ -57,7 +58,8 @@ ProbInput::ProbInput(std::fstream &input) {
}

ProbInput::~ProbInput() {
std::map<std::string, Billing*>::iterator map_it = billing_imap.cbegin();
std::map<std::string, Billing*>::iterator map_it;
map_it = billing_imap.cbegin();
while (map_it != billing_imap.cend()) {
delete map_it->second;
++map_it;
Expand Down Expand Up @@ -87,7 +89,7 @@ void ProbInput::ReadDataSection(std::fstream &input) {
int num_incompatible_regions;
input >> id1 >> id2 >> num_incompatible_regions;
string region_id;
for (int j = 0; j < num_incompatible_regions; ++j){
for (int j = 0; j < num_incompatible_regions; ++j) {
intput >> region_id;
int region_ind = region_imap[region_id];
assert(region_ind < num_region);
Expand Down Expand Up @@ -156,7 +158,7 @@ void ProbInput::CreateBillingStategy(std::fstream &input) {
string tmp, id, type;
char buffer[kBufSize];
input >> tmp;
for(int i = 0; i < num_billing; ++i) {
for (int i = 0; i < num_billing; ++i) {
input >> id >> type;
input.getline(buffer, kBufSize);
if (type == "bt1") {
Expand Down Expand Up @@ -195,7 +197,7 @@ void ProbInput::CreateBillingStategy(std::fstream &input) {
void ProbInput::GroupOrder() {
OrderGroup og(order_vec[0]);
ordergroup_vec.push_back(og);
for (int i = 1; i < num_order; i++){
for (int i = 1; i < num_order; i++) {
int og_size = ordergroup_vec.size();
for (int j = 0; j < og_size; ++j) {
if (ordergroup_vec[j].IsGroupCompatible(order_vec[i])) {
Expand Down
1 change: 1 addition & 0 deletions data/prob_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <map>
#include <utility>
#include <cassert>
#include "data/carrier.h"
#include "data/vehicle.h"
#include "data/client.h"
Expand Down
2 changes: 1 addition & 1 deletion data/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
void RoutePlan::AddOrder(int order_index, unsigned day, unsigned vid) {
int &rid = plan[vid][day];
if (rid != -1) {
routes[rid].AddOrder(order_index);
routes[rid].push_back(order_index);
} else {
routes.push_back(Route(order_index, day, vid, false));
rid = routes.size() - 1;
Expand Down
25 changes: 22 additions & 3 deletions data/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ class Route {
day(d), vehicle(vi), exc_list(ex), orders(1, oid) { }
Route(std::vector<int> ov):
day(0), vehicle(0), exc_list(true), orders(ov) { }
Route(const Route &r): day(r.day), vehicle(r.vehicle),
exc_list(r.exc_list), orders(r.orders) { }
int size() const { return orders.size(); }
unsigned length(const ProbInput&) const;
unsigned demand(const ProbInput&) const;
unsigned get_day() const { return day; }
unsigned get_vehicle() const { return vehicle; }
bool IsExcList() const { return exc_list; }
void AddOrder(int order_index) { orders.push_back(order_index); }
void push_back(int order_index) { orders.push_back(order_index); }
void erase(unsigned pos) { orders.erase(orders.cbegin() + pos); }
void insert(unsigned pos, int order) {
orders.insert(orders.cbegin() + pos, order);
}
const int& operator[] (int i) const { return orders[i]; }
int& operator[] (int i) { return orders[i]; }
Route& operator=(const Route &r) {
day = r.day;
vehicle = r.vehicle;
orders = r.orders;
return *this;
}
private:
int day, vehicle;
bool exc_list;
Expand All @@ -28,21 +40,28 @@ class Route {
class RoutePlan {
public:
RoutePlan(const ProbInput& pi): in(pi) { Allocate(); }
RoutePlan(const RoutePlan &rp):
in(rp.pi), routes(rp.routes), plan(rp.plan) { }
void AddOrder(int , unsigned, unsigned, bool);
void AddRoute(const Route &r) { routes.push_back(r); }
int size() const { return routes.size(); }
int get_est(int route, int order) const { return timetable[route][order]; }
// int get_est(int route, int order) const { return timetable[route][order]; }
// int& get_est(int route, int order) { return timetable[route][order]; }
const Route& operator[] (int i) const { return routes[i]; }
Route& operator[] (int i) const { return routes[i]; }
const int& operator() (int veh, int day) const { return plan[veh][day]; }
int& operator() (int veh, int day) { return plan[veh][day]; }
RoutePlan& operator=(const RoutePlan &rp) {
routes = rp.routes;
plan = rp.plan;
return *this;
}
// check whether a route plan is feasible
bool CheckFeasibility();
private:
void Allocate();
ProbInput &in;
std::vector<Route> routes;
std::vector<std::vector<int>> timetable;
std::vector<std::vector<int>> plan;
};
#endif
Loading

0 comments on commit e1a2fd3

Please sign in to comment.