-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generation of weights in API mode [ANT-2196] (#944)
When generating weights.txt, instead of using list of MPS files generated by simulator in the archive, use the list of MPS files generated by XPANSION in output_dir/lp. This makes it compatible with API mode. Also added a cucumber test with a new step to launch xpansion (and fixed the "simulation succeeds" step) --------- Co-authored-by: Jason Maréchal <[email protected]>
- Loading branch information
1 parent
f032ccc
commit bbf7c19
Showing
8 changed files
with
109 additions
and
42 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
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 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 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 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 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,45 @@ | ||
#include <fstream> | ||
|
||
#include "WeightsFileWriter.h" | ||
#include "gtest/gtest.h" | ||
|
||
void writeDummyFileInTempLpDir(std::string name) { | ||
auto tmp_path = std::filesystem::temp_directory_path() / "lp" / name; | ||
std::ofstream writer; | ||
writer.open(tmp_path); | ||
writer << std::endl; | ||
writer.close(); | ||
} | ||
|
||
TEST(WeightsFileWriterTest, CorrectlyWriteWeightsFile) { | ||
auto tempDir = std::filesystem::temp_directory_path() / "lp"; | ||
if (!std::filesystem::is_directory(tempDir)) { | ||
std::filesystem::create_directory(tempDir); | ||
} | ||
writeDummyFileInTempLpDir("problem-1-1--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-1-50--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-2-10--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-2-11--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-2-30--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-3-20--optim-nb-1.mps"); | ||
writeDummyFileInTempLpDir("problem-3-30--optim-nb-1.txt"); | ||
|
||
auto yearly_weight_writer = | ||
YearlyWeightsWriter(std::filesystem::temp_directory_path(), {3, 5, 7}, | ||
"weights_123.txt", {1, 2, 3}); | ||
yearly_weight_writer.CreateWeightFile(); | ||
|
||
std::ifstream reader(tempDir / "weights_123.txt"); | ||
std::string actual((std::istreambuf_iterator<char>(reader)), | ||
std::istreambuf_iterator<char>()); | ||
std::string expected = R"xxx(problem-1-1--optim-nb-1.mps 3 | ||
problem-1-50--optim-nb-1.mps 3 | ||
problem-2-10--optim-nb-1.mps 5 | ||
problem-2-11--optim-nb-1.mps 5 | ||
problem-2-30--optim-nb-1.mps 5 | ||
problem-3-20--optim-nb-1.mps 7 | ||
WEIGHT_SUM 15 | ||
)xxx"; | ||
|
||
EXPECT_EQ(expected, actual); | ||
} |
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,9 @@ | ||
Feature: add weights on MC years | ||
|
||
@slow @short @full-launch | ||
Scenario: handling different weights on MC years in API mode | ||
# For now, only check that the simulation succeeds | ||
# TODO : add more non-regression tests when we have more steps | ||
Given the study path is "examples/SmallTestFiveCandidatesWithWeights" for a study with weights | ||
When I run antares-xpansion in memory with the benders method and 1 proc(s) | ||
Then the simulation succeeds |
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