Skip to content

Commit

Permalink
Remove useless commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
tbittar committed Aug 21, 2024
1 parent 8b7a244 commit 85d1628
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 92 deletions.
28 changes: 0 additions & 28 deletions src/andromede/expression/equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,6 @@
TimeOperatorNode,
)

# from andromede.expression import (
# AdditionNode,
# ComparisonNode,
# DivisionNode,
# ExpressionNode,
# LiteralNode,
# MultiplicationNode,
# NegationNode,
# ParameterNode,
# SubstractionNode,
# VariableNode,
# )
# from andromede.expression.expression import (
# BinaryOperatorNode,
# ExpressionRange,
# InstancesTimeIndex,
# PortFieldAggregatorNode,
# PortFieldNode,
# ScenarioOperatorNode,
# TimeAggregatorNode,
# TimeOperatorNode,
# )


@dataclass(frozen=True)
class EqualityVisitor:
Expand Down Expand Up @@ -95,8 +72,6 @@ def visit(
return self.multiplication(left, right)
if isinstance(left, ComparisonNode) and isinstance(right, ComparisonNode):
return self.comparison(left, right)
# if isinstance(left, VariableNode) and isinstance(right, VariableNode):
# return self.variable(left, right)
if isinstance(left, ParameterNode) and isinstance(right, ParameterNode):
return self.parameter(left, right)
if isinstance(left, ComponentParameterNode) and isinstance(
Expand Down Expand Up @@ -151,9 +126,6 @@ def division(self, left: DivisionNode, right: DivisionNode) -> bool:
def comparison(self, left: ComparisonNode, right: ComparisonNode) -> bool:
return left.comparator == right.comparator and self._visit_operands(left, right)

# def variable(self, left: VariableNode, right: VariableNode) -> bool:
# return left.name == right.name

def parameter(self, left: ParameterNode, right: ParameterNode) -> bool:
return left.name == right.name

Expand Down
3 changes: 0 additions & 3 deletions src/andromede/expression/evaluate_parameters_efficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ class InstancesIndexVisitor(ParameterEvaluationVisitor):
Evaluates an expression given as instances index which should have no variable and constant parameter values.
"""

# def variable(self, node: VariableNode) -> float:
# raise ValueError("An instance index expression cannot contain variable")

# Probably useless as parameter nodes should have already be replaced by component parameter nodes ?
def parameter(self, node: ParameterNode) -> Dict[TimeScenarioIndex, float]:
if not self.context.parameter_is_constant_over_time(node.name):
Expand Down
11 changes: 0 additions & 11 deletions src/andromede/expression/expression_efficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def wrap_in_node(obj: Any) -> ExpressionNodeEfficient:
return obj
elif isinstance(obj, float) or isinstance(obj, int):
return LiteralNode(float(obj))
# else:
# return None
# Do not raise excpetion so that we can return NotImplemented in _apply_if_node
# raise TypeError(f"Unable to wrap {obj} into an expression node")

Expand Down Expand Up @@ -238,10 +236,6 @@ def _are_parameter_nodes_equal(
)


# def _is_parameter_multiplication(node: ExpressionNodeEfficient, name: str):
# return isinstance(node, MultiplicationNode) and ((isinstance(node.left, ParameterNode) and node.left.name == name) or


def _substract_node(
lhs: ExpressionNodeEfficient, rhs: ExpressionNodeEfficient
) -> ExpressionNodeEfficient:
Expand Down Expand Up @@ -644,8 +638,6 @@ def visit(
return self.multiplication(left, right)
if isinstance(left, ComparisonNode) and isinstance(right, ComparisonNode):
return self.comparison(left, right)
# if isinstance(left, VariableNode) and isinstance(right, VariableNode):
# return self.variable(left, right)
if isinstance(left, ParameterNode) and isinstance(right, ParameterNode):
return self.parameter(left, right)
if isinstance(left, ComponentParameterNode) and isinstance(
Expand Down Expand Up @@ -701,9 +693,6 @@ def division(self, left: DivisionNode, right: DivisionNode) -> bool:
def comparison(self, left: ComparisonNode, right: ComparisonNode) -> bool:
return left.comparator == right.comparator and self._visit_operands(left, right)

# def variable(self, left: VariableNode, right: VariableNode) -> bool:
# return left.name == right.name

def parameter(self, left: ParameterNode, right: ParameterNode) -> bool:
return left.name == right.name

Expand Down
11 changes: 0 additions & 11 deletions src/andromede/expression/linear_expression_efficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,12 @@ def sum(
if shift is not None:
return dataclasses.replace(
self,
# coefficient=TimeOperatorNode(
# self.coefficient, TimeOperatorName.SHIFT, InstancesTimeIndex(shift)
# ),
time_operator=TimeShift(InstancesTimeIndex(shift)),
time_aggregator=TimeSum(stay_roll=True),
)
elif eval is not None:
return dataclasses.replace(
self,
# coefficient=TimeOperatorNode(
# self.coefficient,
# TimeOperatorName.EVALUATION,
# InstancesTimeIndex(eval),
# ),
time_operator=TimeEvaluation(InstancesTimeIndex(eval)),
time_aggregator=TimeSum(stay_roll=True),
)
Expand Down Expand Up @@ -902,9 +894,6 @@ def expec(self) -> "LinearExpressionEfficient":
result_expr = LinearExpressionEfficient(result_terms, result_constant)
return result_expr

# def variance(self) -> "ExpressionNode":
# return _apply_if_node(self, lambda x: ScenarioOperatorNode(x, ScenarioOperatorName.Variance))

def sum_connections(self) -> "LinearExpressionEfficient":
if not self.is_zero():
raise ValueError(
Expand Down
12 changes: 0 additions & 12 deletions src/andromede/expression/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ def division(self, node: DivisionNode) -> T:
def comparison(self, node: ComparisonNode) -> T:
...

# @abstractmethod
# def variable(self, node: VariableNode) -> T:
# ...

@abstractmethod
def parameter(self, node: ParameterNode) -> T:
...
Expand All @@ -86,10 +82,6 @@ def parameter(self, node: ParameterNode) -> T:
def comp_parameter(self, node: ComponentParameterNode) -> T:
...

# @abstractmethod
# def comp_variable(self, node: ComponentVariableNode) -> T:
# ...

@abstractmethod
def time_operator(self, node: TimeOperatorNode) -> T:
...
Expand Down Expand Up @@ -119,14 +111,10 @@ def visit(root: ExpressionNodeEfficient, visitor: ExpressionVisitor[T]) -> T:
return visitor.literal(root)
elif isinstance(root, NegationNode):
return visitor.negation(root)
# elif isinstance(root, VariableNode):
# return visitor.variable(root)
elif isinstance(root, ParameterNode):
return visitor.parameter(root)
elif isinstance(root, ComponentParameterNode):
return visitor.comp_parameter(root)
# elif isinstance(root, ComponentVariableNode):
# return visitor.comp_variable(root)
elif isinstance(root, AdditionNode):
return visitor.addition(root)
elif isinstance(root, MultiplicationNode):
Expand Down
8 changes: 0 additions & 8 deletions src/andromede/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ def division(self, node: DivisionNode) -> None:
def comparison(self, node: ComparisonNode) -> None:
raise ValueError("Port definition cannot contain a comparison operator.")

# def variable(self, node: VariableNode) -> None:
# pass

def parameter(self, node: ParameterNode) -> None:
pass

Expand All @@ -276,11 +273,6 @@ def comp_parameter(self, node: ComponentParameterNode) -> None:
"Port definition must not contain a parameter associated to a component."
)

# def comp_variable(self, node: ComponentVariableNode) -> None:
# raise ValueError(
# "Port definition must not contain a variable associated to a component."
# )

def time_operator(self, node: TimeOperatorNode) -> None:
visit(node.operand, self)

Expand Down
23 changes: 4 additions & 19 deletions src/andromede/simulation/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
LinearExpressionEfficient,
RowIndex,
)
from .resolved_linear_expression import ResolvedLinearExpression
from andromede.model.common import ValueType
from andromede.model.constraint import Constraint
from andromede.model.model import PortFieldId
from andromede.study.data import DataBase
from andromede.study.network import Component, Network

from .linear_expression_resolver import LinearExpressionResolver
from .optimization_context import (
BlockBorderManagement,
Expand All @@ -38,10 +40,9 @@
make_data_structure_provider,
make_value_provider,
)
from .resolved_linear_expression import ResolvedLinearExpression
from .strategy import MergedProblemStrategy, ModelSelectionStrategy
from .time_block import TimeBlock
from andromede.study.data import DataBase
from andromede.study.network import Component, Network


def _get_indexing(
Expand Down Expand Up @@ -92,20 +93,11 @@ def _create_constraint(
"""
constraint_indexing = _compute_indexing_structure(context, constraint)

# Perf: Perform linearization (tree traversing) without timesteps so that we can get the number of instances for the expression (from the time_ids of operators)
# linear_expr = context.linearize_expression(0, 0, constraint.expression)
# # Will there be cases where instances > 1 ? If not, maybe just a check that get_number_of_instances == 1 is sufficient ? Anyway, the function should be implemented
# instances_per_time_step = linear_expr.number_of_instances()
# instances_per_time_step = 1

value_provider = make_value_provider(context.opt_context, context.component)
expression_resolver = LinearExpressionResolver(context.opt_context, value_provider)

for block_timestep in context.opt_context.get_time_indices(constraint_indexing):
for scenario in context.opt_context.get_scenario_indices(constraint_indexing):
# linear_expr_at_t = context.linearize_expression(
# block_timestep, scenario, constraint.expression
# )
row_id = RowIndex(block_timestep, scenario)

resolved_expr = expression_resolver.resolve(constraint.expression, row_id)
Expand Down Expand Up @@ -143,13 +135,6 @@ def _create_objective(

obj: lp.Objective = solver.Objective()
for term in resolved_expr.terms:
# TODO : How to handle the scenario operator in a general manner ?
# if isinstance(term.scenario_aggregator, Expectation):
# weight = 1 / opt_context.scenarios
# scenario_ids = range(opt_context.scenarios)
# else:
# weight = 1
# scenario_ids = range(1)
opt_context._solver_variables[term.variable].is_in_objective = True
obj.SetCoefficient(
term.variable,
Expand Down

0 comments on commit 85d1628

Please sign in to comment.