Skip to content

Commit

Permalink
add new Xpress test
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 25, 2024
1 parent f9bbfd6 commit 2a3e10e
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 28,540 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ jobs:
run: |
export PATH=${GITHUB_WORKSPACE}/_build/vcpkg_installed/x64-linux-release/tools/openmpi/bin:$PATH
cd _build
./lp_namer -o ../data_test/tests_lpnamer/tests_integer/test_lpnamer_01_Xpress/output/economy -e contraintes.txt -f integer --unnamed-problems
ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer"
- name: Cache vcpkg binary dir
Expand Down

This file was deleted.

72 changes: 27 additions & 45 deletions src/cpp/lpnamer/main/ProblemGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,28 @@ std::vector<std::shared_ptr<Problem>> ProblemGeneration::getXpansionProblems(
const std::vector<ProblemData>& mpsList, std::filesystem::path& lpDir_,
std::shared_ptr<ArchiveReader> reader,
const Antares::Solver::LpsFromAntares& lps = {}) {
std::cout << "ProblemGeneration::getXpansionProblems()" << LOGLOCATION << std::endl;
std::vector<std::string> problem_names;
std::transform(mpsList.begin(), mpsList.end(),
std::back_inserter(problem_names),
[](ProblemData const &data) { return data._problem_mps; });
switch (mode_.value()) {
case SimulationInputMode::FILE: {
FileProblemsProviderAdapter adapter(lpDir_, problem_names);
return adapter.provideProblems(solver_name, solver_log_manager);
}
case SimulationInputMode::ARCHIVE: {
ZipProblemsProviderAdapter adapter(lpDir_, std::move(reader),
problem_names);
std::cout << "END ProblemGeneration::getXpansionProblems() " << LOGLOCATION << std::endl;

return adapter.provideProblems(solver_name, solver_log_manager);
}
case SimulationInputMode::ANTARES_API: {
XpansionProblemsFromAntaresProvider adapter(lps);
return adapter.provideProblems(solver_name, solver_log_manager);
}
default:
throw LogUtils::XpansionError<std::runtime_error>(
"Unhandled simulation mode", LOGLOCATION);
std::vector<std::string> problem_names;
std::transform(mpsList.begin(), mpsList.end(),
std::back_inserter(problem_names),
[](ProblemData const& data) { return data._problem_mps; });
switch (mode_.value()) {
case SimulationInputMode::FILE: {
FileProblemsProviderAdapter adapter(lpDir_, problem_names);
return adapter.provideProblems(solver_name, solver_log_manager);
}
case SimulationInputMode::ARCHIVE: {
ZipProblemsProviderAdapter adapter(lpDir_, std::move(reader),
problem_names);
return adapter.provideProblems(solver_name, solver_log_manager);
}
case SimulationInputMode::ANTARES_API: {
XpansionProblemsFromAntaresProvider adapter(lps);
return adapter.provideProblems(solver_name, solver_log_manager);
}
default:
throw LogUtils::XpansionError<std::runtime_error>(
"Unhandled simulation mode", LOGLOCATION);
}
}

void ProblemGeneration::RunProblemGeneration(
Expand Down Expand Up @@ -268,20 +265,16 @@ void ProblemGeneration::RunProblemGeneration(

auto solver_log_manager = SolverLogManager(log_file_path);
Couplings couplings;
std::cout << LOGLOCATION << std::endl;
LinkProblemsGenerator linkProblemsGenerator(
lpDir_, links, solver_name_, logger, solver_log_manager, rename_problems);
std::shared_ptr<ArchiveReader> reader =
antares_archive_path.empty() ? std::make_shared<ArchiveReader>()
: InstantiateZipReader(antares_archive_path);
std::cout << LOGLOCATION << std::endl;

/* Main stuff */
std::cout << LOGLOCATION << std::endl;
std::vector<std::shared_ptr<Problem>> xpansion_problems = getXpansionProblems(
solver_log_manager, solver_name_, mpsList, lpDir_, reader, lps_);

std::cout << LOGLOCATION << std::endl;
std::vector<std::pair<std::shared_ptr<Problem>, ProblemData>>
problems_and_data;
for (int i = 0; i < xpansion_problems.size(); ++i) {
Expand All @@ -291,10 +284,8 @@ void ProblemGeneration::RunProblemGeneration(
} else {
xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps;
problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i));
std::cout << LOGLOCATION << std::endl;
}
}
std::cout << LOGLOCATION << std::endl;
auto mps_file_writer = std::make_shared<MPSFileWriter>(lpDir_);
std::for_each(
std::execution::par, problems_and_data.begin(), problems_and_data.end(),
Expand All @@ -305,23 +296,18 @@ void ProblemGeneration::RunProblemGeneration(
case SimulationInputMode::FILE:
variables_provider = std::make_shared<ProblemVariablesFileAdapter>(
data, links, logger, lpDir_);
std::cout << LOGLOCATION << std::endl;
break;
case SimulationInputMode::ARCHIVE:
if (rename_problems) {
std::cout << LOGLOCATION << std::endl;
variables_provider = std::make_shared<ProblemVariablesZipAdapter>(
reader, data, links, logger);
std::cout << LOGLOCATION << std::endl;
variables_provider = std::make_shared<ProblemVariablesZipAdapter>(
reader, data, links, logger);
} else {
std::cout << LOGLOCATION << std::endl;
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
std::cout << LOGLOCATION << std::endl;
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
}
break;
case SimulationInputMode::ANTARES_API:
case SimulationInputMode::ANTARES_API:
variables_provider =
std::make_shared<ProblemVariablesFromProblemAdapter>(
problem, links, logger);
Expand All @@ -330,11 +316,9 @@ std::cout << LOGLOCATION << std::endl;
(*logger)(LogUtils::LOGLEVEL::ERR) << "Undefined mode";
break;
}
std::cout << LOGLOCATION << std::endl;
linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(),
variables_provider.get(),
mps_file_writer.get());
std::cout << LOGLOCATION << std::endl;
});

if (!weights_file.empty()) {
Expand All @@ -345,14 +329,12 @@ std::cout << LOGLOCATION << std::endl;
reader->Close();
reader->Delete();
}
std::cout << LOGLOCATION << std::endl;
MasterGeneration master_generation(
xpansion_output_dir, links, additionalConstraints, couplings,
master_formulation, solver_name_, logger, solver_log_manager);
(*logger)(LogUtils::LOGLEVEL::INFO)
<< "Problem Generation ran in: "
<< format_time_str(problem_generation_timer.elapsed()) << std::endl;
std::cout << LOGLOCATION << std::endl;
}
void ProblemGeneration::set_solver(std::filesystem::path study_dir, ProblemGenerationLog::ProblemGenerationLogger* logger) {
SettingsReader settingsReader(study_dir / "user" / "expansion" / "settings.ini", logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ class Problem : public SolverAbstract {
void read_basis(const std::filesystem::path &filename) override {
solver_abstract_->read_basis(filename);
}

void add_stream(std::ostream &stream) { solver_abstract_->add_stream(stream); };
};

#endif // ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
1 change: 0 additions & 1 deletion src/cpp/lpnamer/problem_modifier/LinkProblemsGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void LinkProblemsGenerator::treat(
IProblemVariablesProviderPort *variable_provider, IProblemWriter *writer) {
auto in_prblm =
problem_provider->provide_problem(_solver_name, solver_log_manager_);
in_prblm->add_stream(std::cout);

treat(problem_name, couplings, in_prblm.get(), variable_provider, writer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ std::shared_ptr<Problem> ZipProblemProviderAdapter::provide_problem(
ZipProblemProviderAdapter::problem_name_;
auto in_prblm = std::make_shared<Problem>(
factory.create_solver(solver_name, solver_log_manager));
std::cout << LOGLOCATION << std::endl;

in_prblm->read_prob_mps(lp_mps_name);
std::cout << LOGLOCATION << std::endl;
return in_prblm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ ZipProblemsProviderAdapter::provideProblems(
/*std::transform preserves order of element*/
problem_names_.begin(), problem_names_.end(), problems.begin(),
[&](auto name) {
std::cout << LOGLOCATION << std::endl;
ZipProblemProviderAdapter problem_provider(lp_dir_, name,
archive_reader_);
return problem_provider.provide_problem(solver_name,
solver_log_manager);
ZipProblemProviderAdapter problem_provider(lp_dir_, name,
archive_reader_);
return problem_provider.provide_problem(solver_name,
solver_log_manager);
});
return problems;
}
Expand Down
14 changes: 11 additions & 3 deletions tests/end_to_end/lpnamer/test_lpnamerEndToEnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
DATA_TEST_RELAXED = DATA_TEST / "tests_lpnamer" / "tests_relaxed"
TEST_LP_INTEGER_01 = DATA_TEST_INTEGER / \
"test_lpnamer_01" / "output" / "economy"
TEST_LP_INTEGER_01_XPRESS = DATA_TEST_INTEGER / \
"test_lpnamer_01_Xpress" / "output" / "economy"
TEST_LP_INTEGER_XPRESS = DATA_TEST_INTEGER / \
"test_lpnamer_Xpress" / "output" / "economy"
TEST_LP_INTEGER_02 = DATA_TEST_INTEGER / \
"test_one_link_one_candidate_1week" / "output" / "economy/"
TEST_LP_INTEGER_MULTIPLE_CANDIDATES_SIMPLE_PROB = DATA_TEST_INTEGER / "test_one_link_two_candidates_simple_prob" \
Expand All @@ -34,12 +34,15 @@
/ "economy"
test_data = [
(TEST_LP_INTEGER_01, "integer"),
(TEST_LP_INTEGER_01_XPRESS, "integer"),
(TEST_LP_INTEGER_02, "integer"),
(TEST_LP_RELAXED_01, "relaxed"),
(TEST_LP_RELAXED_02, "relaxed")
]

test_data_xpress = [
(TEST_LP_INTEGER_XPRESS, "integer")
]

class OptionType(Enum):
ARCHIVE = 1
OUTPUT = 2
Expand Down Expand Up @@ -109,6 +112,11 @@ def test_lp_directory_files(install_dir, test_dir, master_mode, option_mode, set
launch_and_compare_lp_with_reference_output(install_dir, master_mode, setup_lp_directory)


@pytest.mark.parametrize("test_dir, master_mode", test_data_xpress)
def test_lp_directory_files(install_dir, test_dir, master_mode, setup_lp_directory, tmp_path):
launch_and_compare_lp_with_reference_archive(install_dir, master_mode, setup_lp_directory)


@pytest.mark.parametrize("test_dir", test_data_multiple_candidates)
@pytest.mark.parametrize("master_mode", ["integer"])
@pytest.mark.parametrize("option_mode", [OptionType.ARCHIVE, OptionType.OUTPUT])
Expand Down

0 comments on commit 2a3e10e

Please sign in to comment.