coin-or / SHOT

A solver for mixed-integer nonlinear optimization problems
https://shotsolver.dev
Eclipse Public License 2.0
117 stars 25 forks source link

use of uninit value, probably Results::currentDualBound #152

Closed svigerske closed 2 years ago

svigerske commented 2 years ago

I'm getting this:

 Performing bound tightening on reformulated problem.
  - Bounds for 2 variables tightened in 0.22 s and 2 passes.
  - Objective bounds are: [0, 2e+100]
==2342834== Conditional jump or move depends on uninitialised value(s)
==2342834==    at 0x583429C: SHOT::DualSolver::checkDualSolutionCandidates() (DualSolver.cpp:52)
==2342834==    by 0x583402E: SHOT::DualSolver::addDualSolutionCandidate(SHOT::DualSolution) (DualSolver.cpp:31)
==2342834==    by 0x5B36FD7: SHOT::TaskPerformBoundTightening::run() (TaskPerformBoundTightening.cpp:146)
==2342834==    by 0x5B3D7E8: SHOT::TaskReformulateProblem::TaskReformulateProblem(std::shared_ptr<SHOT::Environment>) (TaskReformulateProblem.cpp:282)
==2342834==    by 0x58C542D: std::__detail::_MakeUniq<SHOT::TaskReformulateProblem>::__single_object std::make_unique<SHOT::TaskReformulateProblem, std::shared_ptr<SHOT::Environment>&>(std::shared_ptr<SHOT::Environment>&) (unique_ptr.h:1065)
==2342834==    by 0x589FCAE: SHOT::Solver::setProblem(std::shared_ptr<SHOT::Problem>, std::shared_ptr<SHOT::Problem>, std::shared_ptr<SHOT::IModelingSystem>) (Solver.cpp:469)
==2342834==    by 0x59AE784: SHOT::Solver::setProblem(std::shared_ptr<SHOT::Problem>, std::shared_ptr<SHOT::IModelingSystem>) (Solver.h:68)
==2342834==    by 0x59AD659: shtCallSolver (EntryPointsGAMS.cpp:202)
==2342834==    by 0x59ADDFA: C__shtCallSolver (EntryPointsGAMS.cpp:270)
==2342834==    by 0x52D592B: GMSCONF_tgmsconf_DOT_sccallsolver(GMSCONF_tgmsconf_OD_S*, int, void*, void*) (gmsconf.c:2783)
==2342834==    by 0x52C905D: libsolver(unsigned char*, unsigned char*, unsigned char const*, GMOMDODEFEX_tgmomodel_OD_S**, GEVDOORG_tgmsenvironment_OD_S**) (gevdoorg.c:3091)
==2342834==    by 0x52CA760: GEVDOORG_tgmsenvironment_DOT_gevcallsolver(GEVDOORG_tgmsenvironment_OD_S*, void*, unsigned char const*, unsigned char const*, int, int, unsigned char const*, unsigned char const*, double, int, int, double, double, void**, unsigned char*) (gevdoorg.c:3480)
==2342834==  Uninitialised value was created by a heap allocation
==2342834==    at 0x4846003: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2342834==    by 0x58CF040: std::__new_allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (new_allocator.h:137)
==2342834==    by 0x58CD796: std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (alloc_traits.h:464)
==2342834==    by 0x58CBD97: std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<SHOT::Results, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> >&) (allocated_ptr.h:98)
==2342834==    by 0x58CA133: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<SHOT::Results, std::allocator<void>, std::shared_ptr<SHOT::Environment>&>(SHOT::Results*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<SHOT::Environment>&) (shared_ptr_base.h:969)
==2342834==    by 0x58C8917: std::__shared_ptr<SHOT::Results, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<SHOT::Environment>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<SHOT::Environment>&) (shared_ptr_base.h:1712)
==2342834==    by 0x58C6CDC: std::shared_ptr<SHOT::Results>::shared_ptr<std::allocator<void>, std::shared_ptr<SHOT::Environment>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<SHOT::Environment>&) (shared_ptr.h:464)
==2342834==    by 0x58C4703: std::shared_ptr<std::enable_if<!std::is_array<SHOT::Results>::value, SHOT::Results>::type> std::make_shared<SHOT::Results, std::shared_ptr<SHOT::Environment>&>(std::shared_ptr<SHOT::Environment>&) (shared_ptr.h:1010)
==2342834==    by 0x589A6F3: SHOT::Solver::Solver(std::shared_ptr<spdlog::sinks::sink>) (Solver.cpp:94)
==2342834==    by 0x59AD080: shtCallSolver (EntryPointsGAMS.cpp:155)
==2342834==    by 0x59ADDFA: C__shtCallSolver (EntryPointsGAMS.cpp:270)
==2342834==    by 0x52D592B: GMSCONF_tgmsconf_DOT_sccallsolver(GMSCONF_tgmsconf_OD_S*, int, void*, void*) (gmsconf.c:2783)

It's about the following line:

            else if(C.objValue > currDualBound && (C.objValue <= currPrimalBound))

Since that is the first valgrind complain, it should be about currDualBound, which was taken from

    double currDualBound = env->results->getCurrentDualBound();

Looks like Results::currentDualBound does not get initialized.