-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
63 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
add_subdirectory(generalized-assignment-problem) | ||
add_subdirectory(knapsack-problem) | ||
add_subdirectory(facility-location-problem) | ||
function(ADD_EXAMPLE NAME) | ||
add_executable(example_${NAME} ${NAME}.example.cpp) | ||
target_link_libraries(example_${NAME} PRIVATE idol) | ||
add_custom_command(TARGET example_${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.data.txt $<TARGET_FILE_DIR:example_${NAME}>) | ||
endfunction() | ||
|
||
add_example(knapsack) | ||
add_example(facility) | ||
add_example(assignment) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Created by henri on 06/04/23. | ||
// | ||
#include <iostream> | ||
#include "idol/problems/knapsack-problem/KP_Instance.h" | ||
#include "idol/modeling.h" | ||
#include "idol/optimizers/wrappers/HiGHS/HiGHS.h" | ||
|
||
using namespace idol; | ||
|
||
int main(int t_argc, const char** t_argv) { | ||
|
||
const auto instance = Problems::KP::read_instance("facility.data.txt"); | ||
|
||
const auto n_items = instance.n_items(); | ||
|
||
Env env; | ||
|
||
// Create model | ||
Model model(env); | ||
|
||
auto x = model.add_vars(Dim<1>(n_items), 0, 1, Binary, "x"); | ||
|
||
model.add_ctr(idol_Sum(j, Range(n_items), instance.weight(j) * x[j]) <= instance.capacity()); | ||
|
||
model.set_obj_expr(idol_Sum(j, Range(n_items), -instance.profit(j) * x[j])); | ||
|
||
// Set optimizer | ||
model.use(HiGHS()); | ||
|
||
// Solve | ||
model.optimize(); | ||
|
||
std::cout << "Objective value = " << model.get_best_obj() << std::endl; | ||
|
||
std::cout << save_primal(model) << std::endl; | ||
|
||
return 0; | ||
} |