Skip to content

Commit

Permalink
Add variant of ScaleExpression that amplifies indicators of children.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed Dec 31, 2023
1 parent eed1fd1 commit eb7579b
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 140 deletions.
8 changes: 8 additions & 0 deletions schedulers/tetrisched/include/tetrisched/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,20 @@ class MaxExpression : public Expression {
};

/// A `ScaleExpression` amplifies the utility of its child by a scalar factor.
/// It can also be used to disregard the utility and amplify the indicator of
/// the child expression by the scalar factor.
class ScaleExpression : public Expression {
private:
/// The scalar factor to amplify the utility of the child by.
TETRISCHED_ILP_TYPE scaleFactor;
/// A boolean indicating if the utility should be disregarded.
/// Instead, the indicator of the child expression is amplified by the
/// scalar factor.
bool disregardUtility;

public:
ScaleExpression(std::string name, TETRISCHED_ILP_TYPE scaleFactor,
bool disregardUtility);
ScaleExpression(std::string name, TETRISCHED_ILP_TYPE scaleFactor);
void addChild(ExpressionPtr child) override;
ParseResultPtr parse(SolverModelPtr solverModel,
Expand Down
1 change: 1 addition & 0 deletions schedulers/tetrisched/include/tetrisched/SolverModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class ObjectiveFunctionT {
ObjectiveFunctionT(ObjectiveType objectiveType);

/// Adds a term to the left-hand side constraint.
void addTerm(T coefficient, const XOrVariableT<T>& term);
void addTerm(T coefficient, std::shared_ptr<VariableT<T>> variable);
void addTerm(T constant);

Expand Down
16 changes: 14 additions & 2 deletions schedulers/tetrisched/python/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,21 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
"scaling factor.\n"
"\nArgs:\n"
" name (str): The name of the ScaleExpression.\n"
" scalingFactor (TETRISCHED_ILP_TYPE): The scaling factor of the "
" scaleFactor (TETRISCHED_ILP_TYPE): The scaling factor of the "
"ScaleExpression.",
py::arg("name"), py::arg("scalingFactor"));
py::arg("name"), py::arg("scaleFactor"))
.def(py::init<std::string, TETRISCHED_ILP_TYPE, bool>(),
"Initializes a ScaleExpression with the given name and "
"scaling factor.\n"
"\nArgs:\n"
" name (str): The name of the ScaleExpression.\n"
" scaleFactor (TETRISCHED_ILP_TYPE): The scaling factor of "
"the ScaleExpression.\n"
" disregardUtility (bool): If true, the utility of the child "
"expression is disregarded, \nand its indicator is amplified by the "
"scale factor instead.",
py::arg("name"), py::arg("scaleFactor"),
py::arg("disregardUtility"));

// Define the LessThanExpression.
py::class_<tetrisched::LessThanExpression, tetrisched::Expression,
Expand Down
16 changes: 14 additions & 2 deletions schedulers/tetrisched/python/stubs/tetrisched_py/strl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,25 @@ class Placement:
"""

class ScaleExpression(Expression):
def __init__(self, name: str, scalingFactor: float) -> None:
@typing.overload
def __init__(self, name: str, scaleFactor: float) -> None:
"""
Initializes a ScaleExpression with the given name and scaling factor.
Args:
name (str): The name of the ScaleExpression.
scaleFactor (TETRISCHED_ILP_TYPE): The scaling factor of the ScaleExpression.
"""
@typing.overload
def __init__(self, name: str, scaleFactor: float, disregardUtility: bool) -> None:
"""
Initializes a ScaleExpression with the given name and scaling factor.
Args:
name (str): The name of the ScaleExpression.
scalingFactor (TETRISCHED_ILP_TYPE): The scaling factor of the ScaleExpression.
scaleFactor (TETRISCHED_ILP_TYPE): The scaling factor of the ScaleExpression.
disregardUtility (bool): If true, the utility of the child expression is disregarded,
and its indicator is amplified by the scale factor instead.
"""

class SolutionResult:
Expand Down
Loading

0 comments on commit eb7579b

Please sign in to comment.