Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/detect xpress at runtime #724

Merged
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3519bf7
start
a-zakir Oct 18, 2023
1cd9fa2
start
a-zakir Oct 18, 2023
d9f7126
add more function
a-zakir Oct 19, 2023
3963904
by default add Xpress in available solvers list
a-zakir Oct 19, 2023
1b7746c
Merge branch 'develop'
a-zakir Oct 19, 2023
45f1a0b
it works!
a-zakir Oct 19, 2023
2e0b58f
it works 2
a-zakir Oct 19, 2023
57461f6
tidy
a-zakir Oct 20, 2023
1c88437
unload unused function
a-zakir Oct 20, 2023
de57ad5
fix conversion path->string
a-zakir Oct 20, 2023
0450e4c
add newline after msf
a-zakir Oct 20, 2023
2393fdd
set xpress dir env var
a-zakir Oct 20, 2023
88ba8c7
windows set env var XPRESSDIR
a-zakir Oct 20, 2023
d784054
update windows getenv method
a-zakir Oct 23, 2023
ca3b226
update getenv
a-zakir Oct 23, 2023
5b8710c
write err in stderr
a-zakir Oct 23, 2023
239c78f
build clean path
a-zakir Oct 23, 2023
f46956a
print clearer err message
a-zakir Oct 23, 2023
d30bdf3
list xpress dir
a-zakir Oct 23, 2023
ea1c4f0
list xpress dir 2
a-zakir Oct 23, 2023
fbd3fda
list xpress dir 3
a-zakir Oct 23, 2023
80a7815
list xpress dir 4
a-zakir Oct 23, 2023
65f0ec1
list xpress dir 5
a-zakir Oct 23, 2023
ccbdf13
remove prepos
a-zakir Oct 24, 2023
682bd83
some move
a-zakir Oct 24, 2023
925a4a7
move header file
a-zakir Oct 24, 2023
9aa3c50
treat warning
a-zakir Oct 24, 2023
b5d1f37
remove prints
a-zakir Oct 24, 2023
d5c55f7
do right
a-zakir Oct 24, 2023
0c9c969
suggestion by @flomnes
a-zakir Nov 10, 2023
daa0971
suggestion by @flomnes
a-zakir Nov 10, 2023
06ed31a
suggestion by @florian
a-zakir Nov 10, 2023
9da5a5a
rename namespace
a-zakir Nov 10, 2023
2ce15ba
remove commented code
a-zakir Nov 10, 2023
562aa15
resolve conflicts
a-zakir Nov 10, 2023
5731bce
init Xpress env if needed
a-zakir Nov 15, 2023
dd28db3
check available Solvers once per program
a-zakir Nov 15, 2023
6340cb2
set Xpress bool check
a-zakir Nov 15, 2023
fa6cbf6
print the right log messages
a-zakir Nov 15, 2023
6aa147d
rename compile unit variable
a-zakir Nov 16, 2023
4a8ad09
tmp disable xpress as this fork doesn't have it
a-zakir Dec 11, 2023
f457cdc
remove comments
a-zakir Dec 11, 2023
3ac1b43
Revert "tmp disable xpress as this fork doesn't have it"
a-zakir Dec 11, 2023
df16339
Merge branch 'feature/detect_xpress_at_runtime' of https://github.com…
a-zakir Dec 11, 2023
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
18 changes: 9 additions & 9 deletions .github/workflows/build_centos7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ jobs:
with:
submodules: true

- name: Checkout xpressmp linux
uses: actions/checkout@v3
with:
token: ${{ secrets.AS_TOKEN }}
repository: rte-france/xpress-mp
path: ${{ env.XPRESSDIR }}
github-server-url: https://github.com
ref: 8.13a
if: matrix.xprs == 'XPRESS-ON'
# - name: Checkout xpressmp linux
# uses: actions/checkout@v3
# with:
# token: ${{ secrets.AS_TOKEN }}
# repository: rte-france/xpress-mp
# path: ${{ env.XPRESSDIR }}
# github-server-url: https://github.com
# ref: 8.13a
# if: matrix.xprs == 'XPRESS-ON'

- name: Download pre-compiled librairies
uses: ./.github/workflows/download-extract-precompiled-libraries-tgz
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/build_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ jobs:
with:
submodules: true

- name: Checkout xpressmp linux
if: matrix.xprs == 'XPRESS-ON'
uses: actions/checkout@v3
with:
repository: rte-france/xpress-mp
path: ${{ env.XPRESSDIR }}
ref: 8.13
token: ${{ secrets.AS_TOKEN }} #reniew token periodically
# - name: Checkout xpressmp linux
# if: matrix.xprs == 'XPRESS-ON'
# uses: actions/checkout@v3
# with:
# repository: rte-france/xpress-mp
# path: ${{ env.XPRESSDIR }}
# ref: 8.13
# token: ${{ secrets.AS_TOKEN }} #reniew token periodically

- name: ccache
uses: hendrikmuhs/[email protected]
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ jobs:
with:
submodules: true

- name: Checkout xpressmp linux
if: matrix.xprs == 'XPRESS-ON'
uses: actions/checkout@v3
with:
repository: rte-france/xpress-mp-temp
path: ${{ env.XPRESSDIR }}
ref: 8.13a
token: ${{ secrets.AS_TOKEN }}
# - name: Checkout xpressmp linux
# if: matrix.xprs == 'XPRESS-ON'
# uses: actions/checkout@v3
# with:
# repository: rte-france/xpress-mp-temp
# path: ${{ env.XPRESSDIR }}
# ref: 8.13a
# token: ${{ secrets.AS_TOKEN }}

- name: Get release
if: github.event_name == 'release' && github.event.action == 'created'
Expand Down Expand Up @@ -141,5 +141,6 @@ jobs:
run: |
set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin
set PATH=%PATH%;${{ env.XPRESS }}
set XPRESSDIR=${{ env.XPRESSDIR }}
cd _build
ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer"
18 changes: 9 additions & 9 deletions .github/workflows/centos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ jobs:
name: user-guide
path: docs/

- name: Checkout xpressmp linux
uses: actions/checkout@v3
with:
token: ${{ secrets.AS_TOKEN }}
repository: rte-france/xpress-mp
path: ${{ env.XPRESSDIR }}
github-server-url: https://github.com
ref: 8.13a
if: matrix.xprs == 'XPRESS-ON'
# - name: Checkout xpressmp linux
# uses: actions/checkout@v3
# with:
# token: ${{ secrets.AS_TOKEN }}
# repository: rte-france/xpress-mp
# path: ${{ env.XPRESSDIR }}
# github-server-url: https://github.com
# ref: 8.13a
# if: matrix.xprs == 'XPRESS-ON'

- name: Configure
shell: bash
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ubuntu-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ jobs:
with:
submodules: true

- name: Checkout xpressmp linux
if: matrix.xprs == 'XPRESS-ON'
uses: actions/checkout@v3
with:
repository: rte-france/xpress-mp
path: ${{ env.XPRESSDIR }}
ref: 8.13a
token: ${{ secrets.AS_TOKEN }} #reniew token periodically
# - name: Checkout xpressmp linux
# if: matrix.xprs == 'XPRESS-ON'
# uses: actions/checkout@v3
# with:
# repository: rte-france/xpress-mp
# path: ${{ env.XPRESSDIR }}
# ref: 8.13a
# token: ${{ secrets.AS_TOKEN }} #reniew token periodically

- name: ccache
uses: hendrikmuhs/[email protected]
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ jobs:
- name: Enable git longpaths
run: git config --system core.longpaths true

- name: Checkout xpressmp linux
if: matrix.xprs == 'XPRESS-ON'
uses: actions/checkout@v3
with:
repository: rte-france/xpress-mp-temp
path: ${{ env.XPRESSDIR }}
ref: 8.13a
token: ${{ secrets.AS_TOKEN }}
# - name: Checkout xpressmp linux
# if: matrix.xprs == 'XPRESS-ON'
# uses: actions/checkout@v3
# with:
# repository: rte-france/xpress-mp-temp
# path: ${{ env.XPRESSDIR }}
# ref: 8.13a
# token: ${{ secrets.AS_TOKEN }}

- name: Get release
if: github.event_name == 'release' && github.event.action == 'created'
Expand Down Expand Up @@ -193,6 +193,7 @@ jobs:
run: |
set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin\
set PATH=%PATH%;${{ env.XPRESS }}
set XPRESSDIR=${{ env.XPRESSDIR }}
cd _build
ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer"

Expand Down
25 changes: 0 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,6 @@ endif()

find_package(jsoncpp CONFIG REQUIRED)

# Third-party solver
## Xpress
if(XPRESS)
message("XPRESS is ${XPRESS}")

#Default xpress install dir
if (NOT XPRESS_ROOT)
if (MSVC)
set(XPRESS_ROOT "C:/xpressmp")
elseif(UNIX)
set(XPRESS_ROOT "/opt/xpressmp")
endif()
endif()

find_package(XPRESS REQUIRED)

# Add solver variables for usage in C++ source code
# There are already some variables defined by SOLVER, -DUSE_XPRESS, -DUSE_CBC
# But they are exclusive, only one can be set to True
# We need to keep COIN-OR at least COIN-OR to True while it is required in lpnamer
# and we want to allow compilation with several solvers so that the user can switch
# the solver without any compilation phase.
# @TODO : I think those parameters should be merged in a future version
add_definitions( -DXPRESS=true )
endif(XPRESS)


## Coin-OR (Clp and CBC solvers)
Expand Down
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ if (COIN_OR)
SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Cbc\n")
SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Coin\n")
endif()
if (XPRESS)
SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Xpress\n")
endif()


#configure file to define antares-solver executable
Expand Down
106 changes: 27 additions & 79 deletions src/cpp/lpnamer/main/RunProblemGeneration.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

#include "RunProblemGeneration.h"

#include <boost/archive/text_iarchive.hpp>
#include <execution>
#include <iostream>

#include "ActiveLinks.h"
#include "AdditionalConstraints.h"
#include "Clock.h"
#include "GeneralDataReader.h"
#include "LauncherHelpers.h"
#include "LinkProblemsGenerator.h"
Expand All @@ -17,14 +15,12 @@
#include "MasterGeneration.h"
#include "MasterProblemBuilder.h"
#include "MpsTxtWriter.h"
#include "ProblemGenerationExeOptions.h"
#include "ProblemVariablesFromProblemAdapter.h"
#include "ProblemVariablesZipAdapter.h"
#include "StringManip.h"
#include "Timer.h"
#include "WeightsFileReader.h"
#include "WeightsFileWriter.h"
#include "XpansionProblemsFromAntaresProvider.h"
#include "ZipProblemsProviderAdapter.h"
#include "config.h"

Expand Down Expand Up @@ -59,6 +55,7 @@ struct Version {
int major;
int minor;
};

std::shared_ptr<ArchiveReader> InstantiateZipReader(
const std::filesystem::path& antares_archive_path);
void ProcessWeights(
Expand Down Expand Up @@ -128,6 +125,7 @@ std::vector<std::shared_ptr<Problem>> getXpansionProblems(
problem_names);
return adapter->provideProblems(solver_name, solver_log_manager);
}

void RunProblemGeneration(
const std::filesystem::path& xpansion_output_dir,
const std::string& master_formulation,
Expand Down Expand Up @@ -169,14 +167,10 @@ void RunProblemGeneration(
auto files_mapper = FilesMapper(antares_archive_path);
auto mpsList = files_mapper.MpsAndVariablesFilesVect();

bool use_zip_implementation = true;
bool use_file_implementation = false;

auto solver_log_manager = SolverLogManager(log_file_path);
Couplings couplings;
LinkProblemsGenerator linkProblemsGenerator(
lpDir_, links, solver_name, logger, solver_log_manager, rename_problems);
if (use_zip_implementation) {
std::shared_ptr<ArchiveReader> reader =
InstantiateZipReader(antares_archive_path);

Expand All @@ -185,79 +179,33 @@ void RunProblemGeneration(
getXpansionProblems(solver_log_manager, solver_name, mpsList, lpDir_,
reader);

std::vector<std::pair<std::shared_ptr<Problem>, ProblemData>>
problems_and_data;
for (int i = 0; i < xpansion_problems.size(); ++i) {
xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps;
problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i));
}
auto mps_file_writer = std::make_shared<MPSFileWriter>(lpDir_);
std::for_each(
std::execution::par, problems_and_data.begin(), problems_and_data.end(),
[&](const auto& problem_and_data) {
const auto& [problem, data] = problem_and_data;
std::shared_ptr<IProblemVariablesProviderPort> variables_provider;
if (rename_problems) {
variables_provider = std::make_shared<ProblemVariablesZipAdapter>(
reader, data, links, logger);
} else {
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
}
linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(),
variables_provider.get(), mps_file_writer.get());
});

reader->Close();
reader->Delete();
} else if (use_file_implementation) {
/* Main stuff */
auto mps_file_writer = std::make_shared<MPSFileWriter>(lpDir_);
linkProblemsGenerator.treatloop(xpansion_output_dir, couplings, mpsList,
std::vector<std::pair<std::shared_ptr<Problem>, ProblemData>>
problems_and_data;
for (int i = 0; i < xpansion_problems.size(); ++i) {
xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps;
problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i));
}
auto mps_file_writer = std::make_shared<MPSFileWriter>(lpDir_);
std::for_each(
std::execution::par, problems_and_data.begin(), problems_and_data.end(),
[&](const auto& problem_and_data) {
const auto& [problem, data] = problem_and_data;
std::shared_ptr<IProblemVariablesProviderPort> variables_provider;
if (rename_problems) {
variables_provider = std::make_shared<ProblemVariablesZipAdapter>(
reader, data, links, logger);
} else {
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
}
linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(),
variables_provider.get(),
mps_file_writer.get());
} else {
std::filesystem::path path =
xpansion_output_dir.parent_path().parent_path() /
"fichierDeSerialisation";
std::ifstream ifs(xpansion_output_dir.parent_path().parent_path() /
"fichierDeSerialisation");
boost::archive::text_iarchive ia(ifs);

LpsFromAntares lps;
ia >> lps;
lps._constant->Mdeb.push_back(lps._constant->NombreDeCoefficients);

XpansionProblemsFromAntaresProvider adapter(lps);
auto xpansion_problems =
adapter.provideProblems(solver_name, solver_log_manager);
std::vector<std::pair<std::shared_ptr<Problem>, ProblemData>>
problems_and_data;
for (int i = 0; i < xpansion_problems.size(); ++i) {
xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps;
problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i));
}

auto reader = InstantiateZipReader(antares_archive_path);
auto mps_file_writer = std::make_shared<MPSFileWriter>(lpDir_);
});

std::for_each(
std::execution::par, problems_and_data.begin(), problems_and_data.end(),
[&](const auto& problem_and_data) {
const auto& [problem, data] = problem_and_data;
std::shared_ptr<IProblemVariablesProviderPort> variables_provider;
if (rename_problems) {
variables_provider = std::make_shared<ProblemVariablesZipAdapter>(
reader, data, links, logger);
} else {
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
}
linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(),
variables_provider.get(), mps_file_writer.get());
});
}
reader->Close();
reader->Delete();

MasterGeneration master_generation(
xpansion_output_dir, links, additionalConstraints, couplings,
Expand Down
Loading
Loading