Skip to content

Commit

Permalink
Merge pull request #648 from AntaresSimulatorTeam/feature/read_variab…
Browse files Browse the repository at this point in the history
…les_from_mps

read variables from mps
  • Loading branch information
JasonMarechal25 authored Oct 9, 2023
2 parents add3931 + 3cc55c0 commit c407a97
Show file tree
Hide file tree
Showing 54 changed files with 548 additions and 242 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
# ===========================================================================

PROJECT(antaresXpansion VERSION 1.1.0)
set(ANTARES_XPANSION_RC 4)
set(ANTARES_XPANSION_RC 0)

# ===========================================================================
# Default parameters
Expand Down
8 changes: 4 additions & 4 deletions antares-version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"antares_version": "8.6.3",
"antares_version_executable": "8.6",
"antares_xpansion_version": "1.1.0-rc4",
"antares_deps_version": "2.0.6",
"antares_version": "8.7.0",
"antares_version_executable": "8.7",
"antares_xpansion_version": "1.1.0",
"antares_deps_version": "2.0.7",
"minizip_ng_version": "3.0.6"
}
7 changes: 3 additions & 4 deletions src/cpp/benders/benders_core/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ void Worker::init(VariableMap const &variable_map,
_solver->set_output_log_level(log_level);
_solver->read_prob_mps(path_to_mps);

int var_index;
_name_to_id = variable_map;

for (auto const &kvp : variable_map) {
var_index = _solver->get_col_index(kvp.first);
_id_to_name[var_index] = kvp.first;
_name_to_id[kvp.first] = var_index;
_id_to_name[kvp.second] = kvp.first;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/merge_mps/include/MergeMPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StandardLp {
std::get<Attribute::INT_VALUE>(_data)[IntAttribute::NROWS] = nrows;
std::get<Attribute::INT_VALUE>(_data)[IntAttribute::NELES] = nelems;

_colNames = solver_p.get_col_names(0, ncols - 1);
_colNames = solver_p.get_col_names();

std::get<Attribute::INT_VECTOR>(_data)[IntVectorAttribute::MSTART].clear();
std::get<Attribute::INT_VECTOR>(_data)[IntVectorAttribute::MSTART].resize(
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define INCLUDE_GUARD

#define PROJECT_NAME "@PROJECT_NAME@"
#define PROJECT_VER "@PROJECT_VERSION@"
#define PROJECT_VER "@PROJECT_VERSION@"
#define PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@"
#define PROJECT_VER_MINOR "@PROJECT_VERSION_MINOR@"
#define PTOJECT_VER_PATCH "@PROJECT_VERSION_PATCH@"
#define ANTARES_VERSION_TAG "@ANTARES_VERSION_TAG@"
#define ANTARES_VERSION "@ANTARES_VERSION@"

#endif // INCLUDE_GUARD
#endif // INCLUDE_GUARD
5 changes: 2 additions & 3 deletions src/cpp/exe/full_run/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ int main(int argc, char** argv) {
xpansion_output_dir / "lp" / "ProblemGenerationLog.txt";
auto logger = ProblemGenerationLog::BuildLogger(
log_file_path, std::cout, "Full Run - Problem Generation");
auto& loggerRef = (*logger);

auto master_formulation = options_parser.MasterFormulation();
auto additionalConstraintFilename_l =
options_parser.AdditionalConstraintsFilename();
auto weights_file = options_parser.WeightsFile();

const auto unnamed_problems = options_parser.UnnamedProblems();
RunProblemGeneration(xpansion_output_dir, master_formulation,
additionalConstraintFilename_l, archive_path, logger,
log_file_path, weights_file);
log_file_path, weights_file, unnamed_problems);

} catch (std::exception& e) {
std::cerr << "error: " << e.what() << std::endl;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/exe/lpnamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ int main(int argc, char** argv) {
auto additionalConstraintFilename_l =
options_parser.AdditionalConstraintsFilename();
auto weights_file = options_parser.WeightsFile();
auto unnamed_problems = options_parser.UnnamedProblems();
RunProblemGeneration(xpansion_output_dir, master_formulation,
additionalConstraintFilename_l, archive_path, logger,
log_file_path, weights_file);
log_file_path, weights_file, unnamed_problems);

return 0;
} catch (std::exception& e) {
Expand Down
17 changes: 10 additions & 7 deletions src/cpp/helpers/AntaresArchiveUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vector>

#include "ArchiveReader.h"
#include "include/helpers/StringUtils.h"
#include "StringManip.h"

const std::string CRITERION_FILES_PREFIX = "criterion";
const std::string CONSTRAINTS_FILES_PREFIX = "constraints";
Expand All @@ -15,29 +15,33 @@ const std::string MPS_FILES_EXTENSION = ".mps";

bool isCriterionFile(const std::filesystem::path &file_name) {
auto file_name_str = file_name.string();
return StringUtils::contains(file_name_str, CRITERION_FILES_PREFIX) &&
return StringManip::StringUtils::contains(file_name_str,
CRITERION_FILES_PREFIX) &&
!file_name.has_root_path();
}
bool isVariablesFile(const std::filesystem::path &file_name) {
auto file_name_str = file_name.string();
return StringUtils::contains(file_name_str, VARIABLES_FILES_PREFIX) &&
return StringManip::StringUtils::contains(file_name_str,
VARIABLES_FILES_PREFIX) &&
!file_name.has_root_path();
}
bool isConstraintsFile(const std::filesystem::path &file_name) {
auto file_name_str = file_name.string();
return StringUtils::contains(file_name_str, CONSTRAINTS_FILES_PREFIX) &&
return StringManip::StringUtils::contains(file_name_str,
CONSTRAINTS_FILES_PREFIX) &&
!file_name.has_root_path();
}

bool isAreaFile(const std::filesystem::path &file_name) {
auto file_name_str = file_name.string();
return StringUtils::contains(file_name_str, AREA_FILES_PREFIX) &&
return StringManip::StringUtils::contains(file_name_str, AREA_FILES_PREFIX) &&
!file_name.has_root_path();
}

bool isIntercoFile(const std::filesystem::path &file_name) {
auto file_name_str = file_name.string();
return StringUtils::contains(file_name_str, INTERCO_FILES_PREFIX) &&
return StringManip::StringUtils::contains(file_name_str,
INTERCO_FILES_PREFIX) &&
!file_name.has_root_path();
}

Expand All @@ -48,7 +52,6 @@ bool IsAntaresMpsFile(const std::filesystem::path &file_name) {

int32_t AntaresArchiveUpdater::MinizipErase(void *reader, void *writer) {
mz_zip_file *file_info = NULL;
const char *filename_in_zip = NULL;

int32_t err = MZ_OK;
uint8_t zip_cd = 0;
Expand Down
10 changes: 4 additions & 6 deletions src/cpp/helpers/ArchiveWriter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _ARCHIVEWRITER_H
#define _ARCHIVEWRITER_H
#pragma once

#include <vector>

Expand All @@ -11,7 +10,7 @@ class ArchiveWriter : public ArchiveIO {
void* pmz_zip_writer_instance_ = nullptr;
void* pzip_handle_ = nullptr;
void Create() override;
mz_zip_file fileInfo_ = {0};
mz_zip_file fileInfo_ = {};

int32_t CloseInternal();
void DeleteInternal();
Expand All @@ -30,6 +29,5 @@ class ArchiveWriter : public ArchiveIO {
int32_t AddFileInArchive(const std::filesystem::path& FileToAdd);
int32_t AddPathInArchive(const std::filesystem::path& path_to_add,
const std::filesystem::path& root_path);
void* InternalPointer() const { return pmz_zip_writer_instance_; }
};
#endif // _ARCHIVEWRITER_H
void* InternalPointer() const override { return pmz_zip_writer_instance_; }
};
3 changes: 1 addition & 2 deletions src/cpp/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_library (helpers STATIC
${CMAKE_CURRENT_SOURCE_DIR}/solver_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/solver_utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/JsonXpansionReader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StringUtils.cpp AntaresVersionProvider.cpp AntaresVersionProvider.h
AntaresVersionProvider.cpp AntaresVersionProvider.h
${CMAKE_CURRENT_SOURCE_DIR}/OptionsParser.h
${CMAKE_CURRENT_SOURCE_DIR}/OptionsParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ArchiveIO.h
Expand All @@ -43,7 +43,6 @@ get_target_property(xpansion_interfaces_path xpansion_interfaces INTERFACE_INCLU

target_include_directories (helpers
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
${JSON_INC_PATH}/jsoncpp
${xpansion_interfaces_path}
Expand Down
11 changes: 0 additions & 11 deletions src/cpp/helpers/StringUtils.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions src/cpp/helpers/include/helpers/StringUtils.h

This file was deleted.

7 changes: 4 additions & 3 deletions src/cpp/helpers/solver_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ void solver_chgbounds(SolverAbstract::Ptr solver_p,
void solver_rename_vars(SolverAbstract *outSolver_p,
const std::vector<std::string> &names_p) {

for (int i = 0; i < outSolver_p->get_ncols(); i++)
{
outSolver_p->chg_col_name(i, names_p[i]);
if (const auto ncols = outSolver_p->get_ncols(); ncols == names_p.size()) {
for (int i = 0; i < ncols; i++) {
outSolver_p->chg_col_name(i, names_p[i]);
}
}
}
1 change: 0 additions & 1 deletion src/cpp/lpnamer/helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# ===========================================================================

add_library (lp_namer_helper STATIC
${CMAKE_CURRENT_SOURCE_DIR}/common_lpnamer.h
${CMAKE_CURRENT_SOURCE_DIR}/ColumnToChange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ColumnToChange.h
${CMAKE_CURRENT_SOURCE_DIR}/ProblemGenerationLogger.h
Expand Down
48 changes: 0 additions & 48 deletions src/cpp/lpnamer/helper/common_lpnamer.h

This file was deleted.

12 changes: 6 additions & 6 deletions src/cpp/lpnamer/input_reader/CandidatesINIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "INIReader.h"
#include "LogUtils.h"
#include "helpers/StringUtils.h"
#include "StringManip.h"

CandidatesINIReader::CandidatesINIReader(
const std::filesystem::path &antaresIntercoFile,
Expand Down Expand Up @@ -85,7 +85,7 @@ std::vector<std::string> CandidatesINIReader::ReadLineByLineArea(
std::string line;
while (std::getline(stream, line)) {
if (!line.empty() && line.front() != '#') {
result.push_back(StringUtils::ToLowercase(line));
result.push_back(StringManip::StringUtils::ToLowercase(line));
}
}
return result;
Expand Down Expand Up @@ -146,10 +146,10 @@ CandidateData CandidatesINIReader::readCandidateSection(
const std::filesystem::path &candidateFile, const INIReader &reader,
const std::string &sectionName) const {
CandidateData candidateData;
candidateData.name =
StringUtils::ToLowercase(getStrVal(reader, sectionName, "name"));
candidateData.link_name =
StringUtils::ToLowercase(getStrVal(reader, sectionName, "link"));
candidateData.name = StringManip::StringUtils::ToLowercase(
getStrVal(reader, sectionName, "name"));
candidateData.link_name = StringManip::StringUtils::ToLowercase(
getStrVal(reader, sectionName, "link"));
size_t i = candidateData.link_name.find(" - ");
if (i != std::string::npos) {
candidateData.linkor = candidateData.link_name.substr(0, i);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/lpnamer/input_reader/GeneralDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void GeneralDataIniReader::SetPlaylistResetOption() {
void GeneralDataIniReader::SetPlaylistYearLists() {
std::string current_section = "";
for (const auto& line : file_lines_) {
current_section = ReadPlaylist(current_section, common_lpnamer::trim(line));
current_section = ReadPlaylist(current_section, StringManip::trim(line));
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/cpp/lpnamer/input_reader/GeneralDataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "INIReader.h"
#include "ProblemGenerationLogger.h"
#include "common_lpnamer.h"
#include "StringManip.h"

class IniFileNotFound : public std::runtime_error {
public:
Expand All @@ -21,21 +21,19 @@ class IniFileNotFound : public std::runtime_error {
class IniReaderUtils {
public:
static bool LineIsNotASectionHeader(const std::string& line) {
return line.find('=') != std::string::npos;
return StringManip::split(StringManip::trim(line), '=').size() == 2;
}

static std::string ReadSectionHeader(const std::string& line) {
auto str = common_lpnamer::trim(line);
auto str = StringManip::trim(line);
str.erase(std::remove(str.begin(), str.end(), '['), str.end());
str.erase(std::remove(str.begin(), str.end(), ']'), str.end());
return str;
}

static std::pair<std::string, int> GetKeyValFromLine(
const std::string& line) {
auto key = common_lpnamer::trim(common_lpnamer::split(line, '=')[0]);
auto val = std::atoi(
common_lpnamer::trim(common_lpnamer::split(line, '=')[1]).c_str());
static std::pair<std::string, int> GetKeyValFromLine(std::string_view line) {
auto key = StringManip::trim(StringManip::split(line, '=')[0]);
auto val = std::stoi(StringManip::trim(StringManip::split(line, '=')[1]));
return {key, val};
}
};
Expand Down
1 change: 1 addition & 0 deletions src/cpp/lpnamer/input_reader/LinkProfileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ANTARESXPANSION_LINKPROFILEREADER_H

#include <filesystem>
#include <map>

#include "Candidate.h"
#include "LinkProfile.h"
Expand Down
5 changes: 2 additions & 3 deletions src/cpp/lpnamer/input_reader/MpsTxtWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ void FilesMapper::FillMapWithConstraintsFiles(
YearAndWeek FilesMapper::YearAndWeekFromFileName(
const std::filesystem::path& file_name) const {
auto split_file_name =
common_lpnamer::split(common_lpnamer::trim(file_name.string()), '-');
return {std::atoi(split_file_name[1].c_str()),
std::atoi(split_file_name[2].c_str())};
StringManip::split(StringManip::trim(file_name.string()), '-');
return {std::stoi(split_file_name[1]), std::stoi(split_file_name[2])};
}

std::vector<ProblemData> FilesMapper::MpsAndVariablesFilesVect() {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/lpnamer/input_reader/MpsTxtWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <utility>
#include <vector>

#include "common_lpnamer.h"
#include "StringManip.h"

// a pair to hold double key (year and week)
using YearAndWeek = std::pair<int, int>;
Expand Down
Loading

0 comments on commit c407a97

Please sign in to comment.