Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/ASP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ASP {
Flight m_dummy_flight;

public:
enum class Neighborhood : uint8_t { IntraSwap, InterSwap, IntraMove, InterMove };
std::vector<Flight> flights;

// Constructive heuristics
Expand All @@ -27,7 +28,8 @@ class ASP {

// Local search procedures

void VND(Solution &solution); // NOLINT
void VND(Solution &solution); // NOLINT
void RVND(Solution &solution); // NOLINT

// Neighborhoods

Expand All @@ -42,6 +44,7 @@ class ASP {
Solution parallel_GILS_VND(size_t max_iterations, size_t max_ils_iterations, float alpha); // NOLINT
Solution GILS_VND(size_t max_iterations, size_t max_ils_iterations, double alpha); // NOLINT
Solution GILS_VND_2(size_t max_iterations, size_t max_ils_iterations, double alpha); // NOLINT
Solution GILS_RVND(size_t max_iterations, size_t max_ils_iterations, double alpha); // NOLINT

// Perturbations

Expand Down
40 changes: 39 additions & 1 deletion src/GILS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Solution ASP::GILS_VND(const size_t max_iterations, const size_t max_ils_iterati
best_found.objective = std::numeric_limits<uint32_t>::max();

for (size_t iteration = 0; iteration < max_iterations; ++iteration) {
Solution solution = lowest_release_time_insertion(flights);
Solution solution = rand_lowest_release_time_insertion(flights);

Solution local_best = solution;

Expand Down Expand Up @@ -96,6 +96,44 @@ Solution ASP::GILS_VND(const size_t max_iterations, const size_t max_ils_iterati
return best_found;
}

Solution ASP::GILS_RVND(const size_t max_iterations, const size_t max_ils_iterations, const double alpha) { // NOLINT
Solution best_found;
best_found.objective = std::numeric_limits<uint32_t>::max();

for (size_t iteration = 0; iteration < max_iterations; ++iteration) {
Solution solution = lowest_release_time_insertion(flights);

Solution local_best = solution;

RVND(solution);

size_t ils_iteration = 1;

while (ils_iteration <= max_ils_iterations) {
size_t max_pertubation_iters =
1 + static_cast<size_t>(std::ceil(alpha * static_cast<double>(m_instance.get_num_runways() / 2)));

for (size_t perturbation_iteration = 0; perturbation_iteration < max_pertubation_iters;
++perturbation_iteration) {

random_inter_block_swap(solution);
}
RVND(solution);

if (solution.objective < local_best.objective) {
local_best = solution;
ils_iteration = 0;
}
++ils_iteration;
}

if (local_best.objective < best_found.objective) {
best_found = local_best;
}
}
return best_found;
}

Solution ASP::GILS_VND_2(const size_t max_iterations, const size_t max_ils_iterations, const double alpha) { // NOLINT
Solution best_found;
best_found.objective = std::numeric_limits<uint32_t>::max();
Expand Down
36 changes: 36 additions & 0 deletions src/RVND.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "ASP.hpp"
#include <cassert>

void ASP::RVND(Solution &solution) { // NOLINT
std::vector<Neighborhood> neighborhoods{Neighborhood::IntraSwap, Neighborhood::InterSwap, Neighborhood::IntraMove,
Neighborhood::InterMove};

bool improved = false;
size_t current_neighborhood = 0;

while (not neighborhoods.empty()) {
current_neighborhood = rand() % neighborhoods.size();
switch (neighborhoods[current_neighborhood]) {
case Neighborhood::IntraSwap:
improved = best_improvement_intra_swap(solution);
break;
case Neighborhood::InterSwap:
improved = best_improvement_inter_swap(solution);
break;
case Neighborhood::IntraMove:
improved = best_improvement_intra_move(solution);
break;
case Neighborhood::InterMove:
improved = best_improvement_inter_move(solution);
break;
}
if (improved) {
neighborhoods = {Neighborhood::IntraSwap, Neighborhood::InterSwap, Neighborhood::IntraMove,
Neighborhood::InterMove};

} else {
neighborhoods.erase(neighborhoods.begin() + static_cast<long>(current_neighborhood));
}
}
assert(solution.test_feasibility(m_instance));
}
5 changes: 2 additions & 3 deletions src/VND.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include <iostream>
#include <vector>

enum class Neighborhood : uint8_t { IntraSwap, InterSwap, IntraMove, InterMove };

void ASP::VND(Solution &solution) { // NOLINT
std::vector<Neighborhood> neighborhoods{Neighborhood::IntraSwap, Neighborhood::InterSwap, Neighborhood::IntraMove, Neighborhood::InterMove};
std::vector<Neighborhood> neighborhoods{Neighborhood::IntraSwap, Neighborhood::InterSwap, Neighborhood::IntraMove,
Neighborhood::InterMove};

size_t current_neighborhood = 0;

Expand Down
24 changes: 20 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <filesystem>
#include <iostream>
Expand All @@ -10,13 +11,22 @@
#include "solution.hpp"

int main(int argc, char *argv[]) {
srand(time(NULL));

argparse::ArgumentParser program("ASP");

srand(time(nullptr));

program.add_argument("instance").help("Path to the input file").required();
program.add_argument("--grasp")
.help("Number of GRASP iterations")
.default_value("1") // or no default if you want it required
.scan<'i', size_t>(); // 'i' means integer

program.add_argument("--ils").help("Number of ILS iterations").default_value("10").scan<'i', size_t>();

program.add_argument("--alpha")
.help("Alpha value for GRASP (0.0 to 1.0)")
.default_value("0.01")
.scan<'g', double>(); // 'g' means double (float)

try {
program.parse_args(argc, argv);
Expand All @@ -27,13 +37,19 @@ int main(int argc, char *argv[]) {

std::filesystem::path instance_file_path = program.get<std::string>("instance");

auto grasp_iterations = program.get<size_t>("--grasp");

auto ils_iterations = program.get<size_t>("--ils");

auto alpha = program.get<double>("--alpha");

Instance instance(instance_file_path);

/*instance.print();*/

ASP asp(instance);

Solution s2 = asp.GILS_VND(1, 12, 0.50);
Solution s2 = asp.GILS_RVND(grasp_iterations, ils_iterations, alpha);

s2.print_runway();

Expand All @@ -43,4 +59,4 @@ int main(int argc, char *argv[]) {
// s1.print();

return 0;
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sources = files(
'neighborhood.cpp',
'ASP.cpp',
'VND.cpp',
'RVND.cpp',
'GRASP.cpp',
'GILS.cpp',
'perturbation.cpp'
Expand Down
Loading