Skip to content
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

Build error due to Clp linking (windows,mingw64) #11

Closed
sschnug opened this issue Dec 29, 2019 · 10 comments
Closed

Build error due to Clp linking (windows,mingw64) #11

sschnug opened this issue Dec 29, 2019 · 10 comments

Comments

@sschnug
Copy link

sschnug commented Dec 29, 2019

I'm interested in evaluating this software as emergency/open-source MICQP solver (potentially replacing automatic-differentiation based internals). In regards to my potential use-case, i'm focusing on a mingw-64-based windows build now. Not having binary-releases available maybe indicates all that trouble.

I'm pretty positive, that i solved the preparation of Cbc + Ipopt for now (the tests do). Building SHOT however does not work for me.

I modified some cmake-based scripts (in a rather hacky way) for my case as it will fail to find Cbc + Ipopt otherwise:

FindCBC.cmake

-  set(ENV{PKG_CONFIG_PATH} "${CBC_DIR}/lib/pkgconfig")
+  set(ENV{PKG_CONFIG_PATH} "X:/msys64_coin/usr/local/lib/pkgconfig")

CMakeLists.txt

-  set(ENV{PKG_CONFIG_PATH} "${IPOPT_DIR}/lib/pkgconfig")
+  set(ENV{PKG_CONFIG_PATH} "X:/msys64_coin/usr/local/lib/pkgconfig")

cmake was then started with:

cmake -G "Unix Makefiles" -DHAS_GAMS=False -DHAS_GUROBI=False -DHAS_CPLEX=False -DCMAKE_BUILD_TYPE=Release ..

resulting in:

-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: X:/msys64_coin/mingw64/bin/cc.exe
-- Check for working C compiler: X:/msys64_coin/mingw64/bin/cc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: X:/msys64_coin/mingw64/bin/c++.exe
-- Check for working CXX compiler: X:/msys64_coin/mingw64/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include filesystem
-- Looking for C++ include filesystem - found
-- Performing Test CAN_COMPILE_FS_WITHOUT_LINK
-- Performing Test CAN_COMPILE_FS_WITHOUT_LINK - Failed
-- Performing Test CAN_COMPILE_FS_WITH_LINK
-- Performing Test CAN_COMPILE_FS_WITH_LINK - Success
-- Git hash: 59178b4-dirty
-- Found PkgConfig: X:/msys64_coin/mingw64/bin/pkg-config.exe (found version "0.29.2")
-- Checking for one of the modules 'cbc'
-- Cbc found using Pkg-config:
   Include directories found: X:/msys64_coin/usr/local/include/coin;X:/msys64_coin/usr/local/include/coin/ThirdParty;X:/msys64_coin/usr/local/include/coin;X:/msys64_coin/usr/local/include/coin/ThirdParty
   Library directories found: X:/msys64_coin/usr/local/lib
-- Found CBC: CbcSolver;Cbc;pthread;Cgl;OsiClp;ClpSolver;Clp;coinasl;m;Osi;CoinUtils;bz2;z;lapack;blas;m;coinglpk;m;gmp
-- Checking for one of the modules 'ipopt'
-- Cbc include files will be used from: X:/msys64_coin/usr/local/include/coin;X:/msys64_coin/usr/local/include/coin/ThirdParty;X:/msys64_coin/usr/local/include/coin;X:/msys64_coin/usr/local/include/coin/ThirdParty
-- The following Cbc libraries will be used from: X:/msys64_coin/usr/local/lib
   CbcSolver;Cbc;pthread;Cgl;OsiClp;ClpSolver;Clp;coinasl;m;Osi;CoinUtils;bz2;z;lapack;blas;m;coinglpk;m;gmp
-- Configuring done
-- Generating done
-- Build files have been written to: X:/COIN_BUILD/2/SHOT/build

(mumps may be missing due to my recent experiments; i'm pretty sure i was there on my first approach)

invoking make then results eventually in:

[ 96%] Building CXX object CMakeFiles/SHOTSolver.dir/ThirdParty/ampl/src/os.cc.obj
[ 97%] Linking CXX shared library libSHOTSolver.dll
X:/msys64_coin/usr/local/lib/libClp.a(ClpCholeskyMumps.o):ClpCholeskyMumps.cpp:(.text+0x68): undefined reference to `dmumps_c'
X:/msys64_coin/usr/local/lib/libClp.a(ClpCholeskyMumps.o):ClpCholeskyMumps.cpp:(.text+0x6d): undefined reference to `MPI_Finalize'

This is only a partial output, as further experiments (see comment about mumps above) induced more linking errors, probably because i forgot to prepare Mumps (so this one should be ignored for now):

X:/msys64_coin/usr/local/lib/libClp.a(ClpCholeskyMumps.o):ClpCholeskyMumps.cpp:(.text+0x68): undefined reference to `dmumps_c'

Above further experiments are building Cbc/Clp --without-mumps

Maybe these lines:

#define MPI_COMM_WORLD CLP_MPI_COMM_WORLD
#define JOB_INIT -1
#define JOB_END -2
#define USE_COMM_WORLD -987654
extern "C" {
#include "dmumps_c.h"
// In newer ThirdParty/Mumps, mpi.h is renamed to mumps_mpi.h.
// We get informed about this by having COIN_USE_MUMPS_MPI_H defined.
#ifdef COIN_USE_MUMPS_MPI_H
#include "mumps_mpi.h"
#else
#include "mpi.h"
#endif
}

are a potential source of trouble.

I'm wondering, why the coinbrew-based installs of Cbc never had those linking errors, which SHOT has.

Not being an expert in regards to any of these build-tools, it's hard to tell how to proceed. As i see it, mingw64 only provides a microsoft-based MPI implementation mingw-w64-x86_64-msmpi, but i don't think this is relevant here. Cbc builds fine without it being available, which also makes me wonder if it's really about MPI-backends or some Mumps-internal mpi-headers.

I'm afraid, that there is a limited amount of people trying to build this software for windows yet, and probably even less reading this opened issue. Maybe @svigerske has tried a windows-based install?

But maybe this problem also translates to Linux? I should try a linux-based install later (although this one is also not much fun due to the experimental::filesystem thingy which excludes vanilla Uubuntu-LTS -> SHOT really asks for a very modern build-system; but well; that is fine as i'm only using VirtualBox-based Linux instances).

Has anyone a hint? How did people succeed in compiling SHOT? I suppose, coinbrew will play a role for most (in regards to dependencies).

Thanks for reading!

  • Sascha
@svigerske
Copy link
Member

Seems that Clp was build with use of Mumps, but the Mumps library (coinmumps) is missing in the dependencies:

-- The following Cbc libraries will be used from: X:/msys64_coin/usr/local/lib
   CbcSolver;Cbc;pthread;Cgl;OsiClp;ClpSolver;Clp;coinasl;m;Osi;CoinUtils;bz2;z;lapack;blas;m;coinglpk;m;gmp

I would think that clp.pc in X:/msys64_coin/usr/local/lib/pkgconfig should include a mention of coinmumps in Requires:.

Both dmumps_c and MPI_Finalize should be defined in the Mumps library, whereas the latter is just a dummy function to resolve this symbol (see libseq/mpic.c in the Mumps source). There is no need for a complete MPI backend to use sequential Mumps, libseq/mpic.c takes care of that.

@sschnug
Copy link
Author

sschnug commented Dec 29, 2019

Thanks!

Not sure, what went wrong there, as i was sure Mumps was valid within the coinbrew toolchain.
But doing the Cbc install from scratch (including dependencies like Clp), pkg-config now looks like what you expected and we can continue:

Name: CLP
Description: COIN-OR Linear Programming Solver
URL: https://projects.coin-or.org/Clp
Version: trunk
Libs: -L${libdir} -lClpSolver -lClp 
Cflags: -I${includedir}
Requires: coinasl coinmumps coinglpk coinutils 

Sadly, now i'm getting

[ 97%] Linking CXX shared library libSHOTSolver.dll
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(Problem.cpp.obj):Problem.cpp:(.text+0xbd0): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(Problem.cpp.obj):Problem.cpp:(.text+0xac0b): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(Problem.cpp.obj):Problem.cpp:(.text+0xacf1): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(Problem.cpp.obj):Problem.cpp:(.text+0xb283): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(Problem.cpp.obj):Problem.cpp:(.text+0xb365): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
X:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SHOTSolver.dir/objects.a(ModelingSystemOSiL.cpp.obj):ModelingSystemOSiL.cpp:(.text+0x270b): undefined reference to `std::filesystem::__cxx11::path::_List::_List()'
...
ngRefIcEEDpRKT_[_ZN2mp5ErrorC1IJiEEEN6fmtold15BasicCStringRefIcEEDpRKT_]+0x70): more undefined references to `std::runtime_error::operator=(std::runtime_error&&)' follow
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/SHOTSolver.dir/build.make:1448: libSHOTSolver.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/SHOTSolver.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

which points to the Dual ABI stuff

At the moment, i'm not sure where this comes from, as:

  • mingw64 system is fresh and fully updated
  • the coin-stack a-priori SHOT install was build from source using coinbrew

Not sure, where somewhat got compiled with different ABI settings and why (how is it even possible: i'm using gcc version 9.2.0 (Rev2, Built by MSYS2 project)).

Enough for today :-/

Edit

Still won't do, despite many attempts in regards to --with-default-libstdcxx=c++11 or add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) (0).

coinbrew itself feels very chaotic as in a small change in building-decisions (to fix the negative result) seems to lead to completely different build-paths (what worked last time won't do now, need to continue changing things) when trying to install multiple projects (e.g. cbc + ipopt).

So i wasn't successful but will close the ticket, as the described problem is not there anymore + the remaining problems seem to be more about CoinOR builds and potentially Mingw64-related specifics, not necessarily SHOT-related.

@sschnug sschnug closed this as completed Dec 29, 2019
@sschnug
Copy link
Author

sschnug commented Dec 30, 2019

Success!

Without knowing exactly what went wrong with above, i essentially tried it with a fresh mingw64 install and also did two changes to my workflow. For anyone looking at SHOT + Windows (mingw64), i essentially did:

Setup MSYS2 + mingw64

  • setup mingw64 through msys2
  • start mingw64 shell (blue icon; not the violet one of msys2)
  • Update through pacman -Syu until no more updates (will tell you to close the window in-between iterations)
  • pacman -S mingw-w64-x86_64-cmake git patch tar diffutils pkg-config mingw-w64-x86_64-gcc make mingw-w64-x86_64-gcc-fortran

Prepare dependencies: cbc + ipopt

workflow change (1): instead of messing up sequential building of cbc and ipopt, we can use the fact, that bonmin and SHOT share some similarities, especially their dependencies: both will need cbc + ipopt (without commercials) and not much more (in an asymmetric fashion). Assuming building and installing bonmin:

  • git clone https://github.com/coin-or/coinbrew.git
  • ./coinbrew fetch bonmin --no-prompt --skip='ThirdParty/HSL ThirdParty/FilterSQP ThirdParty/Metis'
    • (i'm skipping Metis due to license; skipping FilterSQP might be redundant)
  • ./coinbrew build bonmin --no-prompt --skip='ThirdParty/HSL ThirdParty/FilterSQP ThirdParty/Metis' --enable-cbc-parallel --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --verbosity 3 --prefix=/usr/local/coin --with-default-libstdcxx=c++11

workflow change (2): we really make sure to use the new ABI (Dual ABI). Not sure, why it should not be used, but better safe then sorry.

(YOUR_MSYS2_BASE/usr/local/coin will now have all those binaries, libs and headers)

Prepare SHOT

Help SHOT finding ipopt: replace path in CMakeLists.txt:

-  set(ENV{PKG_CONFIG_PATH} "${IPOPT_DIR}/lib/pkgconfig")
+  set(ENV{PKG_CONFIG_PATH} "X:/msys64_coin_v3/usr/local/coin/lib/pkgconfig")

Help SHOT finding cbc: replace path in misc/FindCBC.cmake:

-  set(ENV{PKG_CONFIG_PATH} "${CBC_DIR}/lib/pkgconfig")
+  set(ENV{PKG_CONFIG_PATH} "X:/msys64_coin_v3/usr/local/coin/lib/pkgconfig")
  • cmake -G "Unix Makefiles" -DHAS_GAMS=False -DHAS_GUROBI=False -DHAS_CPLEX=False -DCMAKE_BUILD_TYPE=Release ..
    • no commercials here
  • make -j 6

Finally, it will look like:

[ 97%] Linking CXX shared library libSHOTSolver.dll
[ 97%] Built target SHOTSolver
Scanning dependencies of target SHOT
[ 98%] Building CXX object CMakeFiles/SHOT.dir/src/SHOT.cpp.obj
[100%] Linking CXX executable SHOT.exe
[100%] Built target SHOT

Finished

SHOT.exe runs for me and just running an example instance synthes1.osi did look good (although i did not check the values):

(Very) partial output:

...
 ? Options ------------------------------------------------------------------------------------------------------------?

 No options file specified.

 Nondefault options used:

  - Dual.MIP.Solver = 2
  - Primal.Tolerance.TrustLinearConstraintValues = false

  - solver:                  Cbc

 Primal NLP solver:          Ipopt with Ipopt default linear solver

 ...
? Solution report ----------------------------------------------------------------------------------------------------?

 Terminated since relative gap met requirements.

 Globally optimal primal solution found.

 Objective bound (minimization) [dual, primal]:  [6.00426, 6.00976]
 Objective gap absolute / relative:              0.0055012 / 0.000915378

@sschnug sschnug changed the title Build error due to Clp linking Build error due to Clp linking (windows,mingw64) Dec 30, 2019
@andreaslundell
Copy link
Member

@sschnug Great it worked out, and thanks for the detailed compilation instructions. I've linked to them from the official compilation instructions in case somebody else needs them.

@AllenShi666
Copy link

Hello, I am following these steps to try to compile SHOT on windows using mingw64, everything is fine until cmake -G "Unix Makefiles" -DHAS_GAMS=False -DHAS_GUROBI=False -DHAS_CPLEX=False -DCMAKE_BUILD_TYPE=Release .., the error was like CMake Error at CMakeLists.txt:91 (message):
No MIP solver defined. SHOT needs at least one!
. It looks like SHOT still couln't find my Cbc, and I notice that in MY_MSYS2_BASE/usr/local/coin/bin, I only have bonmin.exe, ipopt.exe, cbc.exe, clp.exe, no *.dll files were found anywhere. When I try to run those *.exe files, they were saying liblapack.dll were not found, so are we expecting some .dll files to appear after compiling Bonmin? I did install lapack packge using pacman -S mingw-w64-x86_64-lapack --noconfirm already.

@andreaslundell
Copy link
Member

You should use the switches -DHAS_CBC=on and -DCBC_DIR=<path to CBC>. I do not know if CMake works with =True as well but perhaps you can verify this. Yes you will need a library of Cbc, the executable is not enough, and those could be located in MY_MSYS2_BASE/usr/local/coin/lib.

Do you need to compile SHOT for Windows for some special reason, or could you just use the binaries available here: https://github.com/coin-or/SHOT/releases? These have Cbc and Ipopt included so no need to compile these separately.

@AllenShi666
Copy link

Thanks for the heads up with the new release on windows. I am just wondering is there a example on how to use the binary files to pass in evaluation constrains, etc in a more programmatic way (API callback) instead of use any .nl or .osil file to store the information?

@andreaslundell
Copy link
Member

@AllenShi666 As you noticed, I answered you by mail, but I will include similar information here as well in case somebody else is interested.

You can provide the optimization problem either as a file (.nl/.osil) or as a SHOT problem object (https://github.com/coin-or/SHOT/blob/master/src/Model/Problem.h). For examples, you can have a look at https://github.com/coin-or/SHOT/blob/master/test/ModelTest.cpp, where simple models are created programmatically. There is however thus far no example of solving a problem created, but I will add this in the coming days. For reference, I created an issue on this on GitHub (#79).

So in short, yes, you can create a model using the API (and this is more or less how the GAMS integration is implemented), but unfortunately it is not well documented at the moment.

@andreaslundell
Copy link
Member

@AllenShi666 There is now an example on how to use SHOT in the apiexample branch:

SHOT/test/SolverTest.cpp

Lines 220 to 415 in 1adb35d

bool CreateAndSolveProblem()
{
bool passed = true;
// Initializing the SHOT solver class
auto solver = std::make_unique<SHOT::Solver>();
// Contains the environment variable unique to the created solver instance
auto env = solver->getEnvironment();
solver->updateSetting("Console.LogLevel", "Output", static_cast<int>(E_LogLevel::Off));
solver->updateSetting("Debug.Enable", "Output", true);
// Initializing a SHOT problem class
auto problem = std::make_shared<SHOT::Problem>(env);
problem->name = "ex1223b";
// Creating the variables
auto x1 = std::make_shared<Variable>("x1", 0, E_VariableType::Real, 0.0, 10.0);
auto x2 = std::make_shared<Variable>("x2", 1, E_VariableType::Real, 0.0, 10.0);
auto x3 = std::make_shared<Variable>("x3", 2, E_VariableType::Real, 0.0, 10.0);
auto b4 = std::make_shared<Variable>("b4", 3, E_VariableType::Binary);
auto b5 = std::make_shared<Variable>("b5", 4, E_VariableType::Binary);
auto b6 = std::make_shared<Variable>("b6", 5, E_VariableType::Binary);
auto b7 = std::make_shared<Variable>("b7", 6, E_VariableType::Binary);
// All variables are nonlinear, so need to add expression variables as well
auto nl_x1 = std::make_shared<ExpressionVariable>(x1);
auto nl_x2 = std::make_shared<ExpressionVariable>(x2);
auto nl_x3 = std::make_shared<ExpressionVariable>(x3);
auto nl_b4 = std::make_shared<ExpressionVariable>(b4);
auto nl_b5 = std::make_shared<ExpressionVariable>(b5);
auto nl_b6 = std::make_shared<ExpressionVariable>(b6);
auto nl_b7 = std::make_shared<ExpressionVariable>(b7);
// Adding the variables to the problem
problem->add({ x1, x2, x3, b4, b5, b6, b7 });
// Creating the objective function
// minimize -(sqr((-1) + b4) + sqr((-2) + b5) + sqr((-1) + b6) - log(1 + b7) + sqr((-1) + x1) + sqr((-2) + x2) +
// sqr((-3) + x3))
auto objective = std::make_shared<NonlinearObjectiveFunction>(E_ObjectiveFunctionDirection::Minimize);
problem->add(objective);
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-1), nl_b4)));
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-2), nl_b5)));
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-1), nl_b6)));
objective->add(std::make_shared<ExpressionNegate>(std::make_shared<ExpressionLog>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(1), nl_b7))));
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-1), nl_x1)));
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-2), nl_x2)));
objective->add(std::make_shared<ExpressionSquare>(
std::make_shared<ExpressionSum>(std::make_shared<ExpressionConstant>(-3), nl_x3)));
// Creating the constraint e1: x1 + x2 + x3 + b4 + b5 + b6 <= 5;
auto e1 = std::make_shared<LinearConstraint>(0, "e1", SHOT_DBL_MIN, 5.0);
e1->add(std::make_shared<LinearTerm>(1.0, x1));
e1->add(std::make_shared<LinearTerm>(1.0, x2));
e1->add(std::make_shared<LinearTerm>(1.0, x3));
e1->add(std::make_shared<LinearTerm>(1.0, b4));
e1->add(std::make_shared<LinearTerm>(1.0, b5));
e1->add(std::make_shared<LinearTerm>(1.0, b6));
problem->add(e1);
// Creating the constraint e2: sqr(b6) + sqr(x1) + sqr(x2) + sqr(x3) <= 5.5;
auto e2 = std::make_shared<QuadraticConstraint>(1, "e2", SHOT_DBL_MIN, 5.5);
e2->add(std::make_shared<QuadraticTerm>(1.0, b6, b6));
e2->add(std::make_shared<QuadraticTerm>(1.0, x1, x1));
e2->add(std::make_shared<QuadraticTerm>(1.0, x2, x2));
e2->add(std::make_shared<QuadraticTerm>(1.0, x3, x3));
problem->add(e2);
// Creating the constraint e3: x1 + b4 <= 1.2;
auto e3 = std::make_shared<LinearConstraint>(2, "e3", SHOT_DBL_MIN, 1.2);
e3->add(std::make_shared<LinearTerm>(1.0, x1));
e3->add(std::make_shared<LinearTerm>(1.0, b4));
problem->add(e3);
// Creating the constraint e4: x2 + b5 <= 1.8;
auto e4 = std::make_shared<LinearConstraint>(3, "e4", SHOT_DBL_MIN, 1.8);
e4->add(std::make_shared<LinearTerm>(1.0, x2));
e4->add(std::make_shared<LinearTerm>(1.0, b5));
problem->add(e4);
// Creating the constraint e5: x3 + b6 <= 2.5;
auto e5 = std::make_shared<LinearConstraint>(4, "e5", SHOT_DBL_MIN, 2.5);
e5->add(std::make_shared<LinearTerm>(1.0, x3));
e5->add(std::make_shared<LinearTerm>(1.0, b6));
problem->add(e5);
// Creating the constraint e6: x1 + b7 <= 1.2;
auto e6 = std::make_shared<LinearConstraint>(5, "e6", SHOT_DBL_MIN, 1.2);
e6->add(std::make_shared<LinearTerm>(1.0, x1));
e6->add(std::make_shared<LinearTerm>(1.0, b7));
problem->add(e6);
// Creating the constraint e7: sqr(b5) + sqr(x2) <= 1.64;
auto e7 = std::make_shared<QuadraticConstraint>(6, "e7", SHOT_DBL_MIN, 1.64);
e7->add(std::make_shared<QuadraticTerm>(1.0, b5, b5));
e7->add(std::make_shared<QuadraticTerm>(1.0, x2, x2));
problem->add(e7);
// Creating the constraint e8: sqr(b6) + sqr(x3) <= 4.25;
auto e8 = std::make_shared<QuadraticConstraint>(7, "e8", SHOT_DBL_MIN, 4.25);
e8->add(std::make_shared<QuadraticTerm>(1.0, b6, b6));
e8->add(std::make_shared<QuadraticTerm>(1.0, x3, x3));
problem->add(e8);
// Creating the constraint e9: sqr(b5) + sqr(x3) <= 4.64;
auto e9 = std::make_shared<QuadraticConstraint>(7, "e9", SHOT_DBL_MIN, 4.64);
e9->add(std::make_shared<QuadraticTerm>(1.0, b5, b5));
e9->add(std::make_shared<QuadraticTerm>(1.0, x3, x3));
problem->add(e9);
// Simplify the nonlinear expressions (and extract e.g. the quadratics)
simplifyNonlinearExpressions(problem, true, true, true);
// Finalize the problem object (after this no changes should be made)
problem->updateProperties();
problem->finalize();
solver->setProblem(problem);
// Writing the problem to console
std::cout << '\n';
std::cout << "Problem created:\n\n";
std::cout << env->problem << '\n';
// Writing the reformulated problem to console
std::cout << '\n';
std::cout << "Reformulated problem created:\n\n";
std::cout << env->reformulatedProblem << '\n';
// Solving the problem
solver->solveProblem();
if(solver->getPrimalSolutions().size() > 0)
{
std::cout << std::endl << "Objective value: " << solver->getPrimalSolution().objValue << std::endl;
passed = true;
}
else
{
passed = false;
}
if(!passed)
std::cout << "Cound not solve problem!\n";
std::cout << "Now trying to reuse the created problem while recreating the solver instance with a callback "
"activating everytime a new primal solution is found.\n\n";
auto reformulatedProblem = env->reformulatedProblem; // Since this is a shared pointer it will not be deleted
auto settings = env->settings;
solver = nullptr;
env = nullptr;
// Need to reinitialize the SHOT solver class and update the environment
solver = std::make_unique<SHOT::Solver>();
env = solver->getEnvironment();
solver->updateSetting("Console.LogLevel", "Output", static_cast<int>(E_LogLevel::Off));
// Resetting our problem objects
solver->setProblem(problem, reformulatedProblem);
// Registers a callback that is activated every time a new primal solution is found
solver->registerCallback(E_EventType::NewPrimalSolution, [&env] {
std::cout << "We have a new primal solution: " << env->results->getPrimalBound() << ". In total now "
<< env->solutionStatistics.numberOfFoundPrimalSolutions << " solutions.\n";
});
// Solving the problem
solver->solveProblem();
if(solver->getPrimalSolutions().size() > 0)
{
std::cout << std::endl << "Objective value: " << solver->getPrimalSolution().objValue << std::endl;
passed = true;
}
else
{
passed = false;
}
if(!passed)
std::cout << "Cound not resolve problem!\n";
else
std::cout << "Could reuse the problem instance without problem!\n";
return passed;
}

Using this example code you can create a problem instance directly and then solve the problem using SHOT. Let me know if you need any further assistance.

@damdaepark
Copy link

Hi there,

I almost am succeeding in compiling SHOT... but can I ask how can I handle this error?

[ 95%] Built target SHOTSolutionStrategies
[ 96%] Building CXX object CMakeFiles/SHOTSolver.dir/src/Report.cpp.obj
[ 97%] Building CXX object CMakeFiles/SHOTSolver.dir/src/RootsearchMethod/RootsearchMethodBoost.cpp.obj
[ 98%] Building CXX object CMakeFiles/SHOTSolver.dir/src/Solver.cpp.obj
[ 99%] Linking CXX shared library libSHOTSolver.dll
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lrt: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldl: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsys-2.0: No such file or directory
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/SHOTSolver.dir/build.make:151: libSHOTSolver.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:421: CMakeFiles/SHOTSolver.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

I got this error after I ran commands

cmake -G "Unix Makefiles" -DHAS_CBC=True -DCBC_DIR="/home/Damdae/coinbrew/dist/bin" -DHAS_GUROBI=True -DGUROBI_DIR="C:/Users/Damdae/OneDrive - SNU/Installation Files/solvers/gurobi" -DHAS_AMPL=True -DAMPL_DIR="C:/msys64/home/Damdae/coinbrew/ThirdParty/ASL" -DCMAKE_BUILD_TYPE=Release ..

and consecutively

make -j 6

on MSYS2 MinGW x64. I am trying to compile it on Windows 10 64bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants