-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expr: option acc:_expr for SCIP #237
- Loading branch information
Showing
6 changed files
with
181 additions
and
19 deletions.
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
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,54 @@ | ||
/* | ||
Basic expression-based model API definitions. | ||
Copyright (C) 2024 AMPL Optimization Inc. | ||
Permission to use, copy, modify, and distribute this software and its | ||
documentation for any purpose and without fee is hereby granted, | ||
provided that the above copyright notice appear in all copies and that | ||
both that the copyright notice and this permission notice and warranty | ||
disclaimer appear in supporting documentation. | ||
The author and AMPL Optimization Inc disclaim all warranties with | ||
regard to this software, including all implied warranties of | ||
merchantability and fitness. In no event shall the author be liable | ||
for any special, indirect or consequential damages or any damages | ||
whatsoever resulting from loss of use, data or profits, whether in an | ||
action of contract, negligence or other tortious action, arising out | ||
of or in connection with the use or performance of this software. | ||
Author: Gleb Belov <[email protected]> | ||
*/ | ||
#ifndef MODEL_API_BASE_H | ||
#define MODEL_API_BASE_H | ||
|
||
#include "mp/flat/model_api_base.h" | ||
|
||
namespace mp { | ||
|
||
/// ModelAPIs handling expression trees should derive from | ||
template <class ExprType=void*> | ||
class BasicExprModelAPI | ||
:public BasicFlatModelAPI { | ||
public: | ||
using Expr = ExprType; | ||
/// Placeholder for GetTypeName() | ||
static const char* GetTypeName() { return "BasicExprModelAPI"; } | ||
|
||
/// A ModelAPI accepting NL trees can declare this. | ||
/// | ||
/// - NotAccepted: not compiled | ||
/// - AcceptedButNotRecommended: compiled but off by default (option acc:_expr) | ||
/// - Recommended: on by default | ||
#define ACCEPT_EXPRESSION_INTERFACE(val) \ | ||
static constexpr ExpressionAcceptanceLevel \ | ||
ExpressionInterfaceAcceptanceLevel() { return ExpressionAcceptanceLevel::val; } | ||
|
||
/// Reuse inherited names | ||
USE_BASE_CONSTRAINT_HANDLERS(BasicFlatModelAPI) | ||
|
||
}; | ||
|
||
} // namespace mp | ||
|
||
#endif // MODEL_API_BASE_H |
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
Basic flat model API definitions. | ||
Copyright (C) 2021 AMPL Optimization Inc | ||
Copyright (C) 2024 AMPL Optimization Inc. | ||
Permission to use, copy, modify, and distribute this software and its | ||
documentation for any purpose and without fee is hereby granted, | ||
|
@@ -16,14 +16,12 @@ | |
whatsoever resulting from loss of use, data or profits, whether in an | ||
action of contract, negligence or other tortious action, arising out | ||
of or in connection with the use or performance of this software. | ||
Author: Gleb Belov <[email protected]> | ||
*/ | ||
#ifndef FLAT_MODEL_API_BASE_H_ | ||
#define FLAT_MODEL_API_BASE_H_ | ||
|
||
/** | ||
* Basic definitions for a FlatModelAPI | ||
*/ | ||
|
||
#include <string> | ||
|
||
#include "mp/arrayref.h" | ||
|
@@ -72,7 +70,14 @@ class VarArrayDef { | |
|
||
|
||
/// Level of acceptance of a constraint by a backend | ||
enum ConstraintAcceptanceLevel { | ||
enum class ConstraintAcceptanceLevel { | ||
NotAccepted=0, | ||
AcceptedButNotRecommended=1, | ||
Recommended=2 | ||
}; | ||
|
||
/// Level of acceptance of an expression by a backend | ||
enum class ExpressionAcceptanceLevel { | ||
NotAccepted=0, | ||
AcceptedButNotRecommended=1, | ||
Recommended=2 | ||
|
@@ -110,7 +115,7 @@ enum ConstraintGroup { | |
class BasicFlatModelAPI { | ||
public: | ||
/// Placeholder for GetTypeName() | ||
static const char* GetTypeName() { return "BasicBackendFlatModelAPI"; } | ||
static const char* GetTypeName() { return "BasicFlatModelAPI"; } | ||
/// Placeholder for GetLongName() | ||
static const char* GetLongName() { return nullptr; } | ||
|
||
|
@@ -155,6 +160,7 @@ class BasicFlatModelAPI { | |
Constraint::GetTypeName() + | ||
"'. Provide a handler or a converter method"); | ||
} | ||
|
||
/// Derived backends have to tell C++ to use default handlers if they are needed | ||
/// when they overload AddConstraint(), due to C++ name hiding | ||
#define USE_BASE_CONSTRAINT_HANDLERS(BaseBackend) \ | ||
|
@@ -169,9 +175,14 @@ class BasicFlatModelAPI { | |
|
||
/// By default, we say constraint XYZ is not accepted but... | ||
static constexpr ConstraintAcceptanceLevel AcceptanceLevel(const BasicConstraint*) { | ||
return NotAccepted; | ||
return ConstraintAcceptanceLevel::NotAccepted; | ||
} | ||
|
||
/// By default, no expressions | ||
static constexpr ExpressionAcceptanceLevel \ | ||
ExpressionInterfaceAcceptanceLevel() | ||
{ return ExpressionAcceptanceLevel::NotAccepted; } | ||
|
||
/// Specifically, ask if the solver accepts non-convex quadratic constraints | ||
static constexpr bool AcceptsNonconvexQC() { return false; } | ||
|
||
|
@@ -194,7 +205,7 @@ class BasicFlatModelAPI { | |
#define ACCEPT_CONSTRAINT(ConstrType, level, con_grp) \ | ||
static mp::ConstraintAcceptanceLevel \ | ||
AcceptanceLevel(const ConstrType*) \ | ||
{ return (mp::ConstraintAcceptanceLevel)level; } \ | ||
{ return mp::ConstraintAcceptanceLevel::level; } \ | ||
static constexpr int \ | ||
GroupNumber(const ConstrType*) { return con_grp; } | ||
|
||
|
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