-
Notifications
You must be signed in to change notification settings - Fork 3
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
InitialSolution #31
Merged
Merged
InitialSolution #31
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7734184
Draft idea for InitialSolution
hedtke 5af4a5d
Finish draft of implementation
hedtke ab60524
Test implementation
hedtke 6ff708c
Fix formatting
hedtke 83984d1
Add documentation
hedtke 3d5fae2
Add test case for infeasible solution
hedtke 53ca5a9
Add missing docu
hedtke b7cc7ec
Fix eof
hedtke b153a92
Update changelog
hedtke ec0fbdf
Add InitialSolution::operator()
hedtke 3a4ef7b
Don't use SCIP_Var in InitialSolution
hedtke c2d2acc
Remove comment that was only relevant when plain SCIP data structures…
hedtke 1cc1cd1
Enforce gcc11 to use pre-built binaries
hedtke a156c4f
Switch from ubuntu-latest to ubuntu-22 to ensure GCC11 is present
hedtke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,10 @@ on: | |
|
||
jobs: | ||
coverage: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
env: | ||
CC: gcc-11 | ||
CXX: g++-11 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: turtlebrowser/get-conan@main | ||
|
@@ -55,7 +58,10 @@ jobs: | |
- name: Run Tests | ||
run: ./build/test/Release/tests.exe | ||
test_without_conan: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
env: | ||
CC: gcc-11 | ||
CXX: g++-11 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install parallelism library for C++ | ||
|
@@ -74,11 +80,29 @@ jobs: | |
make -j tests | ||
- name: Run tests | ||
run: ./test/tests | ||
test_release_inx: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest, macos-13 ] | ||
runs-on: ${{ matrix.os }} | ||
test_release_mac: | ||
runs-on: macos-13 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: turtlebrowser/get-conan@main | ||
- name: Run Conan Install | ||
run: | | ||
conan profile detect | ||
pushd ~/.conan2/profiles | ||
sed -i'' -e 's/gnu17/17/g' * | ||
popd | ||
conan install -of . -o with_tests=True --build=missing . | ||
- name: Run CMake | ||
run: cmake --preset conan-release . | ||
- name: Compile | ||
run: cmake --build build/Release --target tests | ||
- name: Run Tests | ||
run: ./build/Release/test/tests | ||
test_release_linux: | ||
runs-on: ubuntu-22.04 | ||
env: | ||
CC: gcc-11 | ||
CXX: g++-11 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: turtlebrowser/get-conan@main | ||
|
@@ -96,7 +120,10 @@ jobs: | |
- name: Run Tests | ||
run: ./build/Release/test/tests | ||
clang_tidy: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
env: | ||
CC: gcc-11 | ||
CXX: g++-11 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: turtlebrowser/get-conan@main | ||
|
@@ -112,7 +139,7 @@ jobs: | |
- name: Run Clang-Tidy | ||
run: clang-tidy-14 -p build/Release source/*.cpp include/**/*.hpp | ||
clang_format: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: DoozyX/[email protected] | ||
|
@@ -121,7 +148,7 @@ jobs: | |
extensions: 'hpp,cpp' | ||
clangFormatVersion: 17 | ||
doxygen: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ssciwr/doxygen-install@v1 | ||
|
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,42 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
namespace scippp { | ||
|
||
// forward declare | ||
class Var; | ||
|
||
/** | ||
* A primal solution to be added to %SCIP's solution pool. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
class InitialSolution { | ||
friend class Model; | ||
//! Variable assignment in the initial solution. | ||
std::map<const Var*, double> m_values {}; | ||
|
||
public: | ||
/** | ||
* Sets the value for a variable in the solution. | ||
* | ||
* @since 1.3.0 | ||
* @param var Variable to assign a value to. | ||
* @param value to assign to the variable. | ||
*/ | ||
void setValue(const Var& var, double value); | ||
|
||
/** | ||
* Access the mutable value assigned to the variable. | ||
* | ||
* Initializes the assigned value to 0 if no value was assigned to the variable so far. | ||
* | ||
* @since 1.3.0 | ||
* @param var Variable to manipulate the value in the solution for. | ||
* @return Mutable value assigned to the variable. | ||
*/ | ||
double& operator()(const Var& var); | ||
}; | ||
|
||
} |
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,15 @@ | ||
#include "scippp/initial_solution.hpp" | ||
|
||
namespace scippp { | ||
|
||
void InitialSolution::setValue(const Var& var, double value) | ||
{ | ||
m_values[&var] = value; | ||
} | ||
|
||
double& InitialSolution::operator()(const Var& var) | ||
{ | ||
return m_values[&var]; | ||
} | ||
|
||
} |
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,57 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <boost/test/data/test_case.hpp> | ||
|
||
#include "scippp/model.hpp" | ||
|
||
using namespace scippp; | ||
using namespace std; | ||
namespace bdata = boost::unit_test::data; | ||
|
||
BOOST_AUTO_TEST_SUITE(InitSolution) | ||
|
||
BOOST_DATA_TEST_CASE(InitialSolutionStored, bdata::make({ 1, 2, 3 }), indexSetToOne) | ||
{ | ||
Model model("Simple"); | ||
auto x1 = model.addVar("x_1", 1, VarType::BINARY); | ||
auto x2 = model.addVar("x_2", 1, VarType::BINARY); | ||
auto x3 = model.addVar("x_3", 1, VarType::BINARY); | ||
model.addConstr(x1 + x2 + x3 <= 1, "upperBound"); | ||
model.setObjsense(Sense::MAXIMIZE); | ||
|
||
InitialSolution is; | ||
is.setValue(x1, indexSetToOne == 1 ? 1 : 0); | ||
is.setValue(x2, indexSetToOne == 2 ? 1 : 0); | ||
is.setValue(x3, indexSetToOne == 3 ? 1 : 0); | ||
BOOST_TEST(model.addSolution(is)); | ||
|
||
BOOST_REQUIRE(model.getNSols() > 0); | ||
auto sol = model.getBestSol(); | ||
BOOST_TEST(x1.getSolValAsInt(sol) == (indexSetToOne == 1 ? 1 : 0)); | ||
BOOST_TEST(x2.getSolValAsInt(sol) == (indexSetToOne == 2 ? 1 : 0)); | ||
BOOST_TEST(x3.getSolValAsInt(sol) == (indexSetToOne == 3 ? 1 : 0)); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(Infeasible) | ||
{ | ||
Model model("Simple"); | ||
auto x1 = model.addVar("x_1", 1, VarType::BINARY); | ||
model.setObjsense(Sense::MAXIMIZE); | ||
InitialSolution is; | ||
is.setValue(x1, 2); | ||
BOOST_TEST(!model.addSolution(is)); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(UpdateSolution) | ||
{ | ||
Model model("Simple"); | ||
const auto& [x1, x2] = model.addVars<2>("x_"); | ||
InitialSolution is; | ||
is(x1) = 4; | ||
is(x1) += 38; | ||
is(x2) += 42; | ||
BOOST_TEST(is(x1) == 42); | ||
BOOST_TEST(is(x2) == 42); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in it's own separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be. Seems to be more overhead to fix the pipeline somewhere else, merge, rebase .... instead of doing it on the fly here :-)