-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_penalty.c
130 lines (115 loc) · 3.07 KB
/
c_penalty.c
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
#include "c_penalty.h"
#include "assert.h"
#include "modification.h"
#include "penalty_common.h"
#include "problem.h"
#include "route.h"
#include "utils.h"
void
c_penalty_init(struct route *r)
{
struct customer *next;
struct customer *prev = depot_head(r);
prev->demand_pf = prev->demand;
for (next = rlist_next_entry(prev, in_route);
!rlist_entry_is_head(next, &r->list, in_route);
next = rlist_next_entry(next, in_route)) {
next->demand_pf =
prev->demand_pf + next->demand;
prev = next;
}
next = depot_tail(r);
next->demand_sf = next->demand;
for (prev = rlist_prev_entry(next, in_route);
!rlist_entry_is_head(prev, &r->list, in_route);
prev = rlist_prev_entry(prev, in_route)) {
prev->demand_sf =
next->demand_sf + prev->demand;
next = prev;
}
}
double
c_penalty_get_penalty(struct route *r)
{
return MAX(0., depot_tail(r)->demand_pf - p.vc);
}
double
c_penalty_get_insert_penalty(struct customer *v, struct customer *w)
{
struct route *r = v->route;
assert(r != NULL);
return MAX(0., depot_tail(r)->demand_pf + w->demand - p.vc);
}
double
c_penalty_get_insert_delta(struct customer *v, struct customer *w)
{
return c_penalty_get_insert_penalty(v, w)
- c_penalty_get_penalty(v->route);
}
double
c_penalty_get_replace_penalty(struct customer *v, struct customer *w)
{
struct route *r = v->route;
assert(r != NULL);
return MAX(0., depot_tail(r)->demand_pf - v->demand + w->demand
- p.vc);
}
double
c_penalty_get_replace_delta(struct customer *v, struct customer *w)
{
return c_penalty_get_replace_penalty(v, w)
- c_penalty_get_penalty(v->route);
}
double
c_penalty_get_eject_penalty(struct customer *v)
{
struct route *r = v->route;
assert(r != NULL);
return MAX(0., depot_tail(r)->demand_pf - v->demand - p.vc);
}
double
c_penalty_get_eject_delta(struct customer *v)
{
return c_penalty_get_eject_penalty(v)
- c_penalty_get_penalty(v->route);
}
/** This probably doesn't make sense for c_penalty and will never be used */
penalty_common_modification_apply_straight_delta(c)
double
c_penalty_one_opt_penalty(struct customer *v, struct customer *w)
{
assert(v->route != w->route);
struct customer *w_plus = rlist_next_entry(w, in_route);
return MAX(0., v->demand_pf + w_plus->demand_sf - p.vc);
}
double
c_penalty_two_opt_penalty_delta(struct customer *v, struct customer *w)
{
assert(v->route != w->route);
return (c_penalty_one_opt_penalty(v, w)
- c_penalty_get_penalty(v->route))
+ (c_penalty_one_opt_penalty(w, v)
- c_penalty_get_penalty(w->route));
}
double
c_penalty_out_relocate_penalty_delta(struct customer *v, struct customer *w)
{
/** This branch will probably never be executed */
if (unlikely(v->route == w->route))
return 0.f;
else {
return c_penalty_get_eject_delta(w)
+ c_penalty_get_insert_delta(v, w);
}
}
double
c_penalty_exchange_penalty_delta(struct customer *v, struct customer *w)
{
/** This branch will probably never be executed */
if (unlikely(v->route == w->route))
return 0.f;
else {
return c_penalty_get_replace_delta(v, w)
+ c_penalty_get_replace_delta(w, v);
}
}