Skip to content

Commit

Permalink
Write default json for benders
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Oct 25, 2023
1 parent bb3768d commit 67dfc35
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cpp/exe/full_run/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <json/json.h>

#include <boost/program_options.hpp>
#include <exception>
#include <iostream>
Expand All @@ -8,8 +10,27 @@
#include "RunProblemGeneration.h"
#include "StudyUpdateRunner.h"
#include "common_mpi.h"
#include "default_json.h"
namespace po = boost::program_options;

void BendersPreActions(std::filesystem::path option_file) {
if (std::filesystem::exists(option_file) &&
std::filesystem::is_regular_file(option_file)) {
return; // TODO: Cas python dejà passé par là. On garde on non ?
}

std::istringstream option_stream(DefaultJson::BendersOptions);
std::string err;
Json::CharReaderBuilder builder;
Json::Value root;
if (!Json::parseFromStream(builder, option_stream, &root, &err)) {
// TODO: log
}

std::ofstream outStream(option_file);
outStream << root;
}

int main(int argc, char** argv) {
mpi::environment env(argc, argv);
mpi::communicator world;
Expand Down Expand Up @@ -48,6 +69,8 @@ int main(int argc, char** argv) {
const auto options_file = options_parser.BendersOptionsFile();
const auto benders_method = options_parser.Method();

BendersPreActions(options_file);

auto benders_factory =
BendersMainFactory(argc_, argv, benders_method, options_file, env, world);
benders_factory.Run();
Expand Down
1 change: 1 addition & 0 deletions src/cpp/full_run/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

add_library (full_run_lib STATIC
${CMAKE_CURRENT_SOURCE_DIR}/FullRunOptionsParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/default_json.h
)


Expand Down
28 changes: 28 additions & 0 deletions src/cpp/full_run/include/default_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by marechaljas on 25/10/23.
//

#pragma once
#include <string>

namespace DefaultJson {
std::string BendersOptions =
"{ \
\"MAX_ITERATIONS\": -1,\n \
\"ABSOLUTE_GAP\": 1.0,\n \
\"RELATIVE_GAP\": 1e-06,\n \
\"RELAXED_GAP\": 1e-05,\n \
\"AGGREGATION\": false,\n \
\"OUTPUTROOT\": \".\",\n \
\"TRACE\": true,\n \
\"SLAVE_WEIGHT\": \"CONSTANT\",\n \
\"SLAVE_WEIGHT_VALUE\": 1,\n \
\"MASTER_NAME\": \"master\",\n \
\"STRUCTURE_FILE\": \"structure.txt\",\n \
\"INPUTROOT\": \".\",\n \
\"CSV_NAME\": \"benders_output_trace\",\n \
\"BOUND_ALPHA\": true,\n \
\"SEPARATION_PARAM\": 0.5,\n \
\"BATCH_SIZE\": 0,\n \
}";
}

0 comments on commit 67dfc35

Please sign in to comment.