jijzepttools.modeling.extract.problem#
Functions#
separate decision variables from the problem: |
|
|
Show decision variable dependency. |
Module Contents#
- separate_decision_variables(problem: jijmodeling.Problem, variables: list[jijzepttools.modeling.utils.type.DecisionVar]) tuple[list[jijzepttools.modeling.utils.type.DecisionVar], list[jijzepttools.modeling.utils.type.DecisionVar]] #
- separate decision variables from the problem:
the specified variables in variables which is included in problem.
not-specifed variables in variables which is included in problem.
- Parameters:
problem (jm.Problem) – problem to be separated
variables (list[DecisionVar]) – variables to be separated
- Returns:
separated variables
- Return type:
tuple[list[DecisionVar], list[DecisionVar]]
Examples
```python >>> import jijmodeling as jm >>> from jijzepttools.modeling.extract.problem import separate_decision_variables >>> x = jm.BinaryVar(“x”) >>> y = jm.BinaryVar(“y”) >>> z = jm.BinaryVar(“z”) >>> w = jm.BinaryVar(“w”) >>> problem = jm.Problem(“test”) >>> problem += x + y + z >>> problem += jm.Constraint(“c1”, w + z <= 1) >>> variables = [x, y] >>> specified_variables, not_specified_variables = separate_decision_variables(problem, variables) >>> sorted(specified_variables, key=lambda x: x.name) [BinaryVar(name=’x’, shape=[]), BinaryVar(name=’y’, shape=[])] >>> sorted(not_specified_variables, key=lambda x: x.name) [BinaryVar(name=’w’, shape=[]), BinaryVar(name=’z’, shape=[])]
- show_decivar_dependency(problem: jijmodeling.Problem) Dict[Tuple[str, Ellipsis], List[str]] #
Show decision variable dependency.
- Parameters:
problem (jm.Problem) – problem
- Returns:
decision variable dependency
- Return type:
Dict[Tuple[str, …], List[str]]
Examples
```python >>> LARGE_CONST = 10000000 >>> c_x = jm.Placeholder(“c_x”, ndim=1) >>> c_y = jm.Placeholder(“c_y”, ndim=1) >>> A_x1 = jm.Placeholder(“A_x1”, ndim=1) >>> A_x2 = jm.Placeholder(“A_x2”, ndim=1) >>> A_y1 = jm.Placeholder(“A_y1”, ndim=1) >>> A_y2 = jm.Placeholder(“A_y2”, ndim=1) >>> x = jm.IntegerVar(“x”, shape=c_x.shape, lower_bound=0, upper_bound=LARGE_CONST) >>> y = jm.IntegerVar(“y”, shape=c_x.shape, lower_bound=0, upper_bound=LARGE_CONST) >>> i = jm.Element(“i”, belong_to=c_x.shape[0])
>>> obj_x = jm.sum([i], c_x[i] * x[i]) >>> obj_y = jm.sum([i], c_y[i] * y[i])
>>> const_x1 = jm.Constraint("const_x1", jm.sum([i], A_x1[i] * x[i]) == 5) >>> const_x2 = jm.Constraint("const_x2", jm.sum([i], A_x2[i] * x[i]) <= 2) >>> const_y1 = jm.Constraint("const_y1", jm.sum([i], A_y1[i] * y[i]) <= 3) >>> const_y2 = jm.Constraint("const_y2", jm.sum([i], A_y2[i] * y[i]) >= 3) >>> # decision variables is in rhs >>> sum_x = jm.sum([i], x[i]) >>> sum_y = jm.sum([i], y[i]) >>> const_xy = jm.Constraint("const_xy", sum_x <= 10 - sum_y) >>> problem = jm.Problem("problem") >>> problem += obj_x + obj_y >>> problem += const_x1 >>> problem += const_y1 >>> problem += const_x2 >>> problem += const_y2 >>> problem += const_xy >>> show_decivar_dependency(problem) {('x',): ['const_x1', 'const_x2'], ('x', 'y'): ['const_xy'], ('y',): ['const_y1', 'const_y2']}