Skip to content

Commit a279f39

Browse files
brute force ils version
1 parent f8577cc commit a279f39

4 files changed

Lines changed: 117 additions & 14 deletions

File tree

include/ASP.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ASP {
6262
void inter_swap(Solution &solution);
6363
void intra_move(Solution &solution);
6464
void inter_move(Solution &solution);
65+
void chain(Solution &Solution);
6566

6667

6768
ASP(Instance &instance);

src/GILS.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,23 @@ Solution ASP::GILS_RVND(const size_t max_iterations, const size_t max_ils_iterat
146146

147147
// if (ils_iteration % 5 == 0) std::cout << "ils = " << ils_iteration << '\n';
148148

149-
auto max_pertubation_iters =
150-
1 + static_cast<size_t>(std::ceil(alpha * static_cast<double>(m_instance.get_num_runways() / 2)));
149+
size_t max_pertubation_iters =
150+
1 /* + static_cast<size_t>(std::ceil(alpha * static_cast<double>(m_instance.get_num_runways() / 2))) */;
151151

152-
if (ils_iteration > 300) max_pertubation_iters += 3;
153-
if (ils_iteration > 600) max_pertubation_iters += 3;
152+
if (ils_iteration < 2000) max_pertubation_iters += ils_iteration / (2000 / m_instance.get_num_runways());
153+
else max_pertubation_iters += (ils_iteration - 2000) / (2000 / m_instance.get_num_runways());
154154

155155
for (size_t perturbation_iteration = 1; perturbation_iteration <= max_pertubation_iters;
156156
++perturbation_iteration) {
157157

158-
if (ils_iteration > 900) P4(solution);
158+
if (ils_iteration > 2000) P4(solution);
159159
else random_inter_block_swap(solution);
160160
}
161161

162162
RVND(solution);
163163

164164
if (solution.objective < local_best.objective) {
165-
std::cout << "ils = " << ils_iteration << '\n';
165+
// std::cout << "ils = " << ils_iteration << '\n';
166166

167167
// local_best <= solution ////////////////////////////////////////
168168
local_best.objective = solution.objective;

src/RVND.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ void ASP::RVND(Solution &solution) { // NOLINT
1212
current_neighborhood = rand() % neighborhoods.size();
1313
switch (neighborhoods[current_neighborhood]) {
1414
case Neighborhood::IntraSwap:
15-
// improved = best_improvement_intra_swap(solution);
16-
improved = first_improvement_intra_swap(solution);
15+
improved = best_improvement_intra_swap(solution);
16+
// improved = first_improvement_intra_swap(solution);
1717
break;
1818
case Neighborhood::InterSwap:
19-
// improved = best_improvement_inter_swap(solution);
20-
improved = first_improvement_inter_swap(solution);
19+
improved = best_improvement_inter_swap(solution);
20+
// improved = first_improvement_inter_swap(solution);
2121
break;
2222
case Neighborhood::IntraMove:
23-
// improved = best_improvement_intra_move(solution);
24-
improved = first_improvement_intra_move(solution);
23+
improved = best_improvement_intra_move(solution);
24+
// improved = first_improvement_intra_move(solution);
2525
break;
2626
case Neighborhood::InterMove:
27-
// improved = best_improvement_inter_move(solution);
28-
improved = first_improvement_inter_move(solution);
27+
improved = best_improvement_inter_move(solution);
28+
// improved = first_improvement_inter_move(solution);
2929
break;
3030
}
3131
if (improved) {

src/perturbation.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,107 @@ void ASP::inter_move(Solution &solution) {
566566
solution.objective += delta;
567567
}
568568

569+
assert(solution.test_feasibility(m_instance));
570+
}
571+
572+
void ASP::chain(Solution &solution) {
573+
for (size_t i = 0; i < m_instance.get_num_runways(); ++i){
574+
size_t best_runway_i = i;
575+
size_t best_runway_j = (i + 1) % m_instance.get_num_runways();
576+
577+
size_t best_flight_i = 0;
578+
size_t best_flight_j = 0;
579+
580+
best_flight_i = rand() % solution.runways[best_runway_i].sequence.size();
581+
best_flight_j = rand() % (solution.runways[best_runway_j].sequence.size() + 1);
582+
583+
uint32_t original_penalty_i = solution.runways[best_runway_i].penalty;
584+
uint32_t original_penalty_j = solution.runways[best_runway_j].penalty;
585+
586+
solution.runways[best_runway_i].sequence[best_flight_i].get().position = best_flight_j;
587+
solution.runways[best_runway_i].sequence[best_flight_i].get().runway = best_runway_j;
588+
solution.runways[best_runway_i].prefix_penalty.pop_back();
589+
solution.runways[best_runway_j].prefix_penalty.push_back(0);
590+
591+
// Add to best_runway_j
592+
if (best_flight_j == solution.runways[best_runway_j].sequence.size()) {
593+
solution.runways[best_runway_j].sequence.push_back(solution.runways[best_runway_i].sequence[best_flight_i]);
594+
} else {
595+
solution.runways[best_runway_j].sequence.push_back(m_dummy_flight);
596+
597+
for (size_t k = solution.runways[best_runway_j].sequence.size() - 1; k > best_flight_j; k--) {
598+
solution.runways[best_runway_j].sequence[k] = solution.runways[best_runway_j].sequence[k - 1];
599+
solution.runways[best_runway_j].sequence[k].get().position = k;
600+
}
601+
602+
solution.runways[best_runway_j].sequence[best_flight_j] = solution.runways[best_runway_i].sequence[best_flight_i];
603+
}
604+
605+
// Remove from best_runway_i
606+
for (size_t k = best_flight_i; k + 1 < solution.runways[best_runway_i].sequence.size(); k++) {
607+
solution.runways[best_runway_i].sequence[k] = solution.runways[best_runway_i].sequence[k + 1];
608+
solution.runways[best_runway_i].sequence[k].get().position = k;
609+
}
610+
solution.runways[best_runway_i].sequence.pop_back();
611+
612+
// Update prefix best_runway_i
613+
if (best_flight_i == 0) {
614+
Flight &current_flight = solution.runways[best_runway_i].sequence[0].get();
615+
current_flight.start_time = current_flight.get_release_time();
616+
solution.runways[best_runway_i].prefix_penalty[1] = 0;
617+
best_flight_i++;
618+
}
619+
620+
for (size_t i = best_flight_i; i < solution.runways[best_runway_i].sequence.size(); i++) {
621+
Flight &current_flight = solution.runways[best_runway_i].sequence[i].get();
622+
Flight &prev_flight = solution.runways[best_runway_i].sequence[i - 1].get();
623+
624+
current_flight.start_time =
625+
std::max(current_flight.get_release_time(),
626+
prev_flight.start_time + prev_flight.get_runway_occupancy_time() +
627+
m_instance.get_separation_time(prev_flight.get_id(), current_flight.get_id()));
628+
629+
solution.runways[best_runway_i].prefix_penalty[i + 1] =
630+
solution.runways[best_runway_i].prefix_penalty[i] +
631+
(current_flight.start_time - current_flight.get_release_time()) * current_flight.get_delay_penalty();
632+
}
633+
634+
// Update prefix best_runway_j
635+
if (best_flight_j == 0) {
636+
Flight &current_flight = solution.runways[best_runway_j].sequence[0].get();
637+
current_flight.start_time = current_flight.get_release_time();
638+
solution.runways[best_runway_j].prefix_penalty[1] = 0;
639+
best_flight_j++;
640+
}
641+
642+
for (size_t j = best_flight_j; j < solution.runways[best_runway_j].sequence.size(); j++) {
643+
Flight &current_flight = solution.runways[best_runway_j].sequence[j].get();
644+
Flight &prev_flight = solution.runways[best_runway_j].sequence[j - 1].get();
645+
646+
current_flight.start_time =
647+
std::max(current_flight.get_release_time(),
648+
prev_flight.start_time + prev_flight.get_runway_occupancy_time() +
649+
m_instance.get_separation_time(prev_flight.get_id(), current_flight.get_id()));
650+
651+
solution.runways[best_runway_j].prefix_penalty[j + 1] =
652+
solution.runways[best_runway_j].prefix_penalty[j] +
653+
(current_flight.start_time - current_flight.get_release_time()) * current_flight.get_delay_penalty();
654+
}
655+
656+
// Update penaltys
657+
solution.runways[best_runway_i].penalty = solution.runways[best_runway_i].prefix_penalty.back();
658+
solution.runways[best_runway_j].penalty = solution.runways[best_runway_j].prefix_penalty.back();
659+
660+
uint32_t delta = 0;
661+
662+
if (solution.runways[best_runway_i].penalty + solution.runways[best_runway_j].penalty < original_penalty_i + original_penalty_j) {
663+
delta = original_penalty_i + original_penalty_j - (solution.runways[best_runway_i].penalty + solution.runways[best_runway_j].penalty);
664+
solution.objective -= delta;
665+
} else {
666+
delta = (solution.runways[best_runway_i].penalty + solution.runways[best_runway_j].penalty) - (original_penalty_i + original_penalty_j);
667+
solution.objective += delta;
668+
}
669+
}
670+
569671
assert(solution.test_feasibility(m_instance));
570672
}

0 commit comments

Comments
 (0)