C++ reference¶
A caller of highs sets options and includes nothing of
ours. The sections after Using it from CMake are for a caller of
mip_heuristics_core, the heuristics without the solver: build the view with
make_problem, receive what the workers find through a SolutionSink, and
run one FJ or LocalMIP worker on a thread of your own with run_until_stopped.
The contracts are in the headers’ comments, which this page does not render:
heuristic_context.h,
solution_sink.h,
fj.h and
local_mip.h.
Using it from CMake¶
Build it inside your project and link highs, HiGHS v1.16.0 with the patch
and the heuristics compiled in, static; #include "Highs.h" works as is:
include(FetchContent)
FetchContent_Declare(mip_heuristics
GIT_REPOSITORY https://github.com/spoorendonk/mip-heuristics.git
GIT_TAG v0.1.12)
FetchContent_MakeAvailable(mip_heuristics)
target_link_libraries(my_solver PRIVATE highs) # the solver
target_link_libraries(my_workers PRIVATE mip_heuristics_core) # the heuristics alone
Clone or submodule in your source tree:
add_subdirectory(mip-heuristics)replaces theFetchContentlines.First configure clones and patches HiGHS: it needs network access.
No
highsof your own (aFetchContentdeclaration or a target) before this one: FetchContent keeps the first declaration, without the patch.Nothing else registers: no tests, lint or bench targets in your build; HiGHS’s own extras (
highs-bin, install rules) come along as upstream defines them. HiGHS’s switches (BUILD_TESTING,BUILD_SHARED_LIBS, …) are set in this project’s scope only.Installed (
cmake --install):highs::highsandhighs::mip_heuristics_corein HiGHS’sfind_package(highs)package; outside CMake,pkg-config --static --libs highs.HiGHS patches of your own:
MIP_HEURISTICS_EXTRA_HIGHS_PATCHES.
The model view¶
-
std::expected<ProblemView, ProblemError> make_problem(const HighsLp &model, ProblemStorage &storage, double feastol, double epsilon)¶
-
struct ProblemView¶
Public Functions
-
inline bool degenerate() const¶
-
inline double objective(const std::vector<double> &x) const¶
Public Members
-
const HighsLp *model = nullptr¶
-
const std::vector<double> *col_lower = nullptr¶
-
const std::vector<double> *col_upper = nullptr¶
-
const std::vector<double> *row_lower = nullptr¶
-
const std::vector<double> *row_upper = nullptr¶
-
const std::vector<double> *col_cost = nullptr¶
-
double offset = 0.0¶
-
const std::vector<HighsVarType> *integrality = nullptr¶
-
const std::vector<HighsInt> *ar_start = nullptr¶
-
const std::vector<HighsInt> *ar_index = nullptr¶
-
const std::vector<double> *ar_value = nullptr¶
-
const CscMatrix *csc = nullptr¶
-
const std::vector<HighsInt> *uplocks = nullptr¶
-
const std::vector<HighsInt> *downlocks = nullptr¶
-
double feastol = 0.0¶
-
double epsilon = 0.0¶
-
HighsInt ncol = 0¶
-
HighsInt nrow = 0¶
-
size_t nnz = 0¶
-
std::vector<double> incumbent¶
-
std::vector<uint8_t> binary¶
-
inline bool degenerate() const¶
-
struct ProblemStorage¶
Public Members
-
std::vector<HighsInt> ar_start¶
-
std::vector<HighsInt> ar_index¶
-
std::vector<double> ar_value¶
-
std::vector<HighsInt> uplocks¶
-
std::vector<HighsInt> downlocks¶
-
CscMatrix csc¶
-
std::vector<double> col_cost¶
-
std::vector<double> col_lower¶
-
std::vector<double> col_upper¶
-
std::vector<double> row_lower¶
-
std::vector<double> row_upper¶
-
std::vector<HighsVarType> integrality¶
-
std::vector<HighsInt> ar_start¶
Budget and execution¶
-
struct HeuristicBudget¶
Public Functions
-
inline bool disabled() const¶
Public Members
-
size_t total = 0¶
-
size_t per_worker = 0¶
-
size_t attempt_cap = 0¶
-
size_t stale = 0¶
-
size_t worker_stale = 0¶
-
bool fj_stall_ends_run = false¶
-
bool local_mip_stall_ends_run = false¶
-
RestartPoint restart = RestartPoint::kDefault¶
-
bool randomize_restart_weights = false¶
-
bool fj_personas = false¶
-
bool fj_exchange = false¶
-
inline bool disabled() const¶
-
inline HeuristicBudget make_until_stopped_budget(size_t attempt_cap, size_t patience)¶
-
struct ExecutionContext¶
Public Functions
-
inline bool past_deadline() const¶
-
inline bool terminated() const¶
-
inline uint32_t worker_seed(int w) const¶
Public Members
-
size_t num_workers¶
-
uint32_t base_seed¶
-
Deadline deadline¶
-
const HighsLogOptions &log_options¶
-
std::function<bool()> terminator¶
-
const std::atomic<bool> *stop = nullptr¶
-
LeastViolatedPoint *least_violated = nullptr¶
-
std::function<bool()> restart_now¶
-
const SharedFjWeights *fj_start_weights = nullptr¶
-
inline bool past_deadline() const¶
-
using RestartSource = std::function<bool(Rng &rng, std::vector<double> &out)>¶
Solutions¶
-
class SolutionSink¶
Public Functions
-
SolutionSink(const std::vector<HighsVarType> &integrality, int source)¶
-
virtual ~SolutionSink() = default¶
-
SolutionSink(const SolutionSink&) = delete¶
-
SolutionSink &operator=(const SolutionSink&) = delete¶
-
OfferResult offer(double objective, const std::vector<double> &solution, const WorkerTrace &trace, size_t effort_at)¶
-
inline size_t accepted() const¶
-
inline bool get_restart(Rng &rng, std::vector<double> &out, SolutionPool::RestartPolicy policy = SolutionPool::RestartPolicy::kMixed)¶
-
inline bool copy_best(std::vector<double> &out)¶
-
inline SolutionPool::SolutionPtr best_ref()¶
-
inline void entry_refs(std::vector<SolutionPool::EntryRef> &out)¶
-
inline double best_objective()¶
-
struct OfferResult¶
-
SolutionSink(const std::vector<HighsVarType> &integrality, int source)¶
-
std::shared_ptr<SolutionPool> make_solution_pool(const std::vector<HighsVarType> &integrality)¶
Workers on your own threads¶
-
size_t fj::run_until_stopped(const ProblemView &problem, const HeuristicBudget &budget, const ExecutionContext &exec, int worker, const RestartSource &source, SolutionSink &sink)¶
-
size_t local_mip::run_until_stopped(const ProblemView &problem, const HeuristicBudget &budget, const ExecutionContext &exec, int worker, const RestartSource &source, SolutionSink &sink)¶