Skip to content

Commit

Permalink
Revert "Ortools" (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov authored Jun 16, 2022
1 parent b795c2b commit 347d6d9
Show file tree
Hide file tree
Showing 88 changed files with 343 additions and 1,204 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ add_prefix(MP_HEADERS include/mp/
model-mgr-base.h model-mgr-with-pb.h
model-mgr-with-std-pb.h model-mgr-with-std-pb.hpp
nl.h nl-reader.h option.h os.h problem.h problem-builder.h
valcvt-base.h valcvt-node.h valcvt-link.h valcvt.h
presolve-base.h presolve-node.h presolve-bridge.h presolve.h
rstparser.h safeint.h sol.h
solver.h solver-opt.h solver-base.h solver-io.h solver-app-base.h solver-app.h
suffix.h utils-file.h utils-hash.h utils-hash-stream.h utils-string.h)

add_prefix(MP_FLAT_HEADERS include/mp/flat/
constr_base.h constr_keeper.h constr_hash.h
constr_std.h constr_static.h constr_functional.h
constr_algebraic.h constr_general.h
constraint_base.h constraint_keeper.h constraint_hash.h
constraints_std.h constraints_static.h constraints_functional.h
constraints_algebraic.h constraints_general.h
context.h
converter.h converter_model.h convert_functional.h
eexpr.h expr_algebraic.h expr_affine.h expr_quadratic.h
Expand Down
31 changes: 3 additions & 28 deletions doc/rst/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,8 @@ solver messages and status reporting,
simplex basis statuses, and other suffix I/O.
Their solver-specific subclasses can be customized for a particular solver.
They rely on the :ref:`model-manager` interface
for model and solution I/O.

As an example, if the driver should read and write simplex basis status suffixes,
the derived Backend class can declare

.. code-block:: c++

ALLOW_STD_FEATURE( BASIS, true )
SolutionBasis GetBasis() override;
void SetBasis(SolutionBasis ) override;

and define the `GetBasis`, `SetBasis` methods.
See the classes' documentation
for further details.
for model and solution I/O. See the classes' documentation
for details.


.. _solver-classes:
Expand Down Expand Up @@ -260,19 +248,6 @@ via the solver's modeling API wrapper:
* `mp::BasicFlatModelAPI` is the interface via which `mp::FlatConverter` addresses
the underlying solver. A subclassed wrapper, such as `mp::GurobiModelAPI`,
signals its accepted constraints and which model conversions are preferable.
For example, `GurobiModelAPI` declares the following in order to natively
receive the logical OR constraint:

.. code-block:: c++

ACCEPT_CONSTRAINT(OrConstraint,
Recommended, // Driver recommends native form
CG_General) // Constraint group for suffix exchange
void AddConstraint(const OrConstraint& );

By default, if the driver does not mark a constraint as acceptable,
`mp::FlatConverter` and its descendants attempt to simplify it. See the
classes' documentation for further details.

* :ref:`value-presolver` transforms solutions and suffixes between the
original NL model and the flat model.
Expand All @@ -283,7 +258,7 @@ via the solver's modeling API wrapper:
Value Presolver
~~~~~~~~~~~~~~~

Class `mp::pre::ValuePresolver` manages transformations of solutions and suffixes
Class `mp::pre::Presolver` manages transformations of solutions and suffixes
between the original NL model and the converted model. For driver architectures
with :ref:`model-manager`, the value presolver object should be shared between
the model converter and the :ref:`Backend <backend-classes>` to enable
Expand Down
7 changes: 0 additions & 7 deletions doc/rst/details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ Namespace mp
:members:


Namespace mp::pre
-----------------

.. doxygennamespace:: mp::pre
:members:


Namespace fmt
-------------

Expand Down
11 changes: 3 additions & 8 deletions doc/rst/model-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ to the solver natively
(if supported; e.g., Gurobi options *acc:and*, *acc:or*).


SOS constraints and non-contiguous variable domains
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOS variable domains
~~~~~~~~~~~~~~~~~~~~

SOS1 is mainly relevant for models that restrict some variables to take a
value from an arbitrary list of values. A simple example:
Expand All @@ -218,11 +218,8 @@ value from an arbitrary list of values. A simple example:
An appropriate SOS1 representation will be
automatically generated from this declaration.

SOS2 are one of the two ways to linearize
:ref:`piecewise-linear expressions <piecewize-linear-expr>` by AMPL.

It is possible to specify SOS1 or SOS2 variables and corresponding "reference rows"
explicitly using AMPL suffixes .sos(no) and .(sos)ref,
explicitly using AMPL suffixes .sosno and .ref,
as described in the solver documentation.
However this requires some study to understand whether SOS1/2 is appropriate
and how to apply it, and we don't recommend going to that trouble unless you
Expand All @@ -246,8 +243,6 @@ or passed to the solver natively
(if supported; e.g., Gurobi options *acc:min*, *acc:max*, *acc:abs*).


.. _piecewize-linear-expr:

Piecewise-linear expressions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
19 changes: 0 additions & 19 deletions include/mp/ampls-c-api.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#ifndef AMPLS_C_INTERFACE_H
#define AMPLS_C_INTERFACE_H

#include <stddef.h>

/*
* A generic C API for MP
*/

#include <stddef.h> // for size_t

#ifdef _WIN32
#define AMPLS_C_EXPORT __declspec(dllexport)
#else
Expand Down Expand Up @@ -50,18 +45,4 @@ AMPLS_C_EXPORT void AMPLSAddMessage(AMPLS_MP_Solver* slv, const char* msg);
const char* const * AMPLSGetMessages(AMPLS_MP_Solver* slv);


/// Set of callbacks provided to a driver for licensing issues
typedef struct CCallbacks_T {
/// If provided, replacement function to create solver environment
/// for a given solver.
void* (*init)();
/// Check if model sizes are allowed; throw if not.
/// Parameters: n_vars, n_alg_con, n_log_con
void (*check)(size_t, size_t, size_t);
/// Return additional text to be displayed on '-v' output
const char* (*additionalText)();
/// Function called after failures to provide additional diagnostics
void (*diagnostics)();
} CCallbacks;

#endif // AMPLS_C_INTERFACE_H
3 changes: 0 additions & 3 deletions include/mp/ampls-cpp-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ AMPLS_MP_Solver* AMPLS__internal__Open(std::unique_ptr<mp::BasicBackend> p_be,
const char* slv_opt);

/// Shut down solver instance. Internal only.
/// Deallocate the mp-related info and the structure itself.
/// Before calling this function, a solver-specific implementation should
/// delete solver_info_ and user_info_ if allocated.
void AMPLS__internal__Close(AMPLS_MP_Solver* slv);

/// Retrieve the Backend
Expand Down
24 changes: 17 additions & 7 deletions include/mp/backend-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
#define BACKEND_BASE_H

#include <string>

extern "C" {
#include "mp/ampls-c-api.h" // for CCallbacks
}
#include <functional>

#include "mp/solver-base.h"

Expand Down Expand Up @@ -79,13 +76,26 @@ class BasicBackend : public BasicSolver {
/// Chance to consider options immediately (open cloud, etc)
virtual void FinishOptionParsing() { }

/// Callbacks typedef
using Callbacks = CCallbacks;
/// Callbacks, e.g., for licensing information
struct Callbacks {
/// If given, has the custom solver GetEnv() method
std::function<void*()> cb_initsolver_;

/// If given, should be called after reading the NL (header)
/// with n_vars, n_algebraic_constr, n_logical_constr
std::function<void (size_t, size_t, size_t)> cb_checkmodel_;

/// If given, provides the license description
std::function<const char*()> cb_license_text_;

/// If given, the function is called to provide additional
// diagnostics if a solver environment cannot be created
std::function<void()> cb_diagnostics_;
};

/// Obtain callbacks
Callbacks& GetCallbacks() { return callbacks_; }


private:
Callbacks callbacks_;
};
Expand Down
4 changes: 2 additions & 2 deletions include/mp/backend-mip.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class MIPBackend : public BaseBackend
/// The basis statuses of vars and cons.
/// MIPBackend handles them in postsolved form (for the NL model)
/// Impl has to perform value pre- / postsolve if needed
/// Getter (returns unpresolved basis)
/// Getter (unpresolved)
virtual SolutionBasis GetBasis() { return {}; }
/// Setter (takes unpresolved basis)
/// Setter (unpresolved)
virtual void SetBasis(SolutionBasis )
{ MP_UNSUPPORTED("MIPBackend::SetBasis"); }
/**
Expand Down
6 changes: 3 additions & 3 deletions include/mp/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DEFAULT_STD_FEATURES_TO( false )

namespace mp {

/// Solution (normally unpresolved)
/// Basis status values of a solution (unpresolved)
struct Solution {
/// primal
std::vector<double> primal;
Expand Down Expand Up @@ -186,7 +186,7 @@ class Backend :
void ReadNL(const std::string& nl_filename,
const std::string& filename_no_ext) override {
GetMM().ReadNLModel(nl_filename, filename_no_ext,
GetCallbacks().check);
GetCallbacks().cb_checkmodel_);
}

/// Input warm start, suffixes, and all that can modify the model.
Expand Down Expand Up @@ -846,7 +846,7 @@ class Backend :
this->set_long_name( fmt::format("{} {}", name, version ) );
this->set_version( fmt::format("AMPL/{} Optimizer [{}]",
name, version ) );
auto lic_cb = GetCallbacks().additionalText;
auto lic_cb = GetCallbacks().cb_license_text_;
if (lic_cb)
this->set_license_info(lic_cb());
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>

#include "mp/utils-hash-stream.h"
#include "mp/flat/constr_std.h"
#include "mp/flat/constraints_std.h"
#include "mp/flat/expr_affine.h"

namespace std {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include "mp/common.h"
#include "mp/flat/model_api_base.h"
#include "mp/flat/constr_hash.h"
#include "mp/flat/constraint_hash.h"
#include "mp/flat/redef/redef_base.h"
#include "mp/valcvt-node.h"
#include "mp/presolve-node.h"

namespace mp {

Expand Down Expand Up @@ -318,10 +318,10 @@ class ConstraintKeeper : public BasicConstraintKeeper {
for (const auto& cont: cons_) {
if (!cont.IsBridged()) {
static_cast<Backend&>(be).AddConstraint(cont.con_);
GetConverter().GetCopyLink().
GetConverter().GetCopyBridge().
AddEntry({
GetValueNode().Select(con_index),
GetConverter().GetValuePresolver().GetTargetNodes().
GetConverter().GetPresolver().GetTargetNodes().
GetConValues()(con_group).Add()
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <cmath>

#include "mp/flat/constr_base.h"
#include "mp/flat/constraint_base.h"
#include "mp/flat/expr_quadratic.h"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Functional flat constraints
*/

#include "mp/flat/constr_static.h"
#include "mp/flat/constraints_static.h"


namespace mp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>
#include <string>

#include "mp/flat/constr_algebraic.h"
#include "mp/flat/constraints_algebraic.h"


namespace mp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Static (non-functional) flat constraints
*/

#include "mp/flat/constr_algebraic.h"
#include "mp/flat/constr_general.h"
#include "mp/flat/constraints_algebraic.h"
#include "mp/flat/constraints_general.h"

#endif // CONSTRAINTS_STATIC_H
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* flat constraints
*/

#include "mp/flat/constr_static.h"
#include "mp/flat/constr_functional.h"
#include "mp/flat/constraints_static.h"
#include "mp/flat/constraints_functional.h"

#endif // STD_CONSTR_H
26 changes: 13 additions & 13 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "mp/solver-base.h"
#include "mp/flat/converter_model.h"
#include "mp/flat/convert_functional.h"
#include "mp/flat/constr_keeper.h"
#include "mp/flat/constr_std.h"
#include "mp/valcvt.h"
#include "mp/flat/constraint_keeper.h"
#include "mp/flat/constraints_std.h"
#include "mp/presolve.h"
#include "mp/flat/redef/std/range_con.h"

namespace mp {
Expand Down Expand Up @@ -881,7 +881,7 @@ class FlatConverter :

void FinishModelInput() {
MPD( ConvertModel() );
if (relax()) // TODO value presolve link?
if (relax()) // TODO bridge?
GetModel().RelaxIntegrality();
GetModel().PushModelTo(GetModelAPI());
}
Expand Down Expand Up @@ -909,9 +909,9 @@ class FlatConverter :
const ModelAPI& GetModelAPI() const { return modelapi_; }
ModelAPI& GetModelAPI() { return modelapi_; }

/// Expose ValuePresolver
const pre::ValuePresolver& GetValuePresolver() const { return value_presolver_; }
pre::ValuePresolver& GetValuePresolver() { return value_presolver_; }
/// Expose Presolver
const pre::Presolver& GetPresolver() const { return presolver_; }
pre::Presolver& GetPresolver() { return presolver_; }

private:
std::unordered_map<double, int> map_fixed_vars_;
Expand Down Expand Up @@ -949,7 +949,7 @@ class FlatConverter :

/// Reuse Presolver's target nodes for all variables
pre::ValueNode& GetVarValueNode()
{ return GetValuePresolver().GetTargetNodes().GetVarValues().MakeSingleKey(); }
{ return GetPresolver().GetTargetNodes().GetVarValues().MakeSingleKey(); }

/// Constraint type's Value Node
template <class Constraint>
Expand Down Expand Up @@ -1067,7 +1067,7 @@ class FlatConverter :
private:
void InitOwnOptions() {
GetEnv().AddOption("cvt:pre:all",
"0/1*: Set to 0 to disable most presolve in the flat converter.",
"0/1*: Set to 0 to disable all presolve in the flat converter.",
options_.preprocessAnything_, 0, 1);
GetEnv().AddOption("cvt:pre:eqresult",
"0/1*: Preprocess reified equality comparison's boolean result bounds.",
Expand Down Expand Up @@ -1099,8 +1099,8 @@ class FlatConverter :

private:
ModelAPIType modelapi_; // We store modelapi in the converter for speed
pre::ValuePresolver value_presolver_;
pre::CopyLink copy_link_ { GetValuePresolver() };
pre::Presolver presolver_;
pre::CopyBridge copy_bridge_ { GetPresolver() };


protected:
Expand Down Expand Up @@ -1232,8 +1232,8 @@ class FlatConverter :
INSTALL_ITEM_CONVERTER(RangeQuadraticConstraintConverter)

public:
/// Presolve link copying values between model items
pre::CopyLink& GetCopyLink() { return copy_link_; }
/// Presolve bridge copying values between model items
pre::CopyBridge& GetCopyBridge() { return copy_bridge_; }
};


Expand Down
Loading

0 comments on commit 347d6d9

Please sign in to comment.