Commit 36479fda authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

propagate activity parameters in whole solver processes.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36766 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1977e9f4
...@@ -58,7 +58,7 @@ class FIFO(DeliverySolver): ...@@ -58,7 +58,7 @@ class FIFO(DeliverySolver):
total_quantity += movement.getQuantity() total_quantity += movement.getQuantity()
return total_quantity return total_quantity
def setTotalQuantity(self, new_quantity): def setTotalQuantity(self, new_quantity, activate_kw=None):
""" """
""" """
result = [] result = []
...@@ -72,14 +72,15 @@ class FIFO(DeliverySolver): ...@@ -72,14 +72,15 @@ class FIFO(DeliverySolver):
if quantity < remaining_quantity: if quantity < remaining_quantity:
result.append((movement, quantity)) result.append((movement, quantity))
remaining_quantity -= quantity remaining_quantity -= quantity
movement.setQuantity(0) movement.edit(quantity=0, delivery_ratio=0, activate_kw=activate_kw)
else: else:
result.append((movement, remaining_quantity)) result.append((movement, remaining_quantity))
movement.setQuantity(quantity - remaining_quantity) movement_quantity = quantity - remaining_quantity
movement.edit(quantity=movement_quantity,
delivery_ratio=movement_quantity / new_quantity,
activate_kw=activate_kw)
remaining_quantity = 0 remaining_quantity = 0
# Return movement, split_quantity tuples # Return movement, split_quantity tuples
for movement in simulation_movement_list:
movement.setDeliveryRatio(movement.getQuantity() / new_quantity)
return result return result
def _getSimulationMovementList(self): def _getSimulationMovementList(self):
......
...@@ -42,7 +42,7 @@ class MinPrice(FIFO): ...@@ -42,7 +42,7 @@ class MinPrice(FIFO):
title = 'MinPrice Solver' title = 'MinPrice Solver'
def setTotalQuantity(self, new_quantity): def setTotalQuantity(self, new_quantity, activate_kw=None):
""" """
""" """
result = [] result = []
...@@ -58,14 +58,15 @@ class MinPrice(FIFO): ...@@ -58,14 +58,15 @@ class MinPrice(FIFO):
if quantity < remaining_quantity: if quantity < remaining_quantity:
result.append((movement, quantity)) result.append((movement, quantity))
remaining_quantity -= quantity remaining_quantity -= quantity
movement.setQuantity(0) movement.edit(quantity=0, delivery_ratio=0, activate_kw=activate_kw)
else: else:
result.append((movement, remaining_quantity)) result.append((movement, remaining_quantity))
movement.setQuantity(quantity - remaining_quantity) movement_quantity = quantity - remaining_quantity
movement.edit(quantity=movement_quantity,
delivery_ratio=movement_quantity / new_quantity,
activate_kw=activate_kw)
remaining_quantity = 0 remaining_quantity = 0
# Return movement, split_quantity tuples # Return movement, split_quantity tuples
for movement in simulation_movement_list:
movement.setDeliveryRatio(movement.getQuantity() / new_quantity)
return result return result
def _getSimulationMovementList(self): def _getSimulationMovementList(self):
......
...@@ -58,7 +58,7 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -58,7 +58,7 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
zope.interface.implements(interfaces.ISolver,) zope.interface.implements(interfaces.ISolver,)
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self, activate_kw=None):
""" """
Adopt new property to simulation movements, with keeping the Adopt new property to simulation movements, with keeping the
original one recorded. original one recorded.
...@@ -69,6 +69,9 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -69,6 +69,9 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
portal_type = self.getPortalObject().portal_types.getTypeInfo(self) portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = portal_type.getTestedPropertyList() solved_property_list = portal_type.getTestedPropertyList()
for simulation_movement in self.getDeliveryValueList(): for simulation_movement in self.getDeliveryValueList():
if activate_kw is not None:
simulation_movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
movement = simulation_movement.getDeliveryValue() movement = simulation_movement.getDeliveryValue()
value_dict = {} value_dict = {}
for solved_property in solved_property_list: for solved_property in solved_property_list:
...@@ -83,6 +86,6 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -83,6 +86,6 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
if not simulation_movement.isPropertyRecorded(property_id): if not simulation_movement.isPropertyRecorded(property_id):
simulation_movement.recordProperty(property_id) simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value) simulation_movement.setMappedProperty(property_id, value)
simulation_movement.expand() simulation_movement.expand(activate_kw=activate_kw)
# Finish solving # Finish solving
self.succeed() self.succeed()
...@@ -60,7 +60,7 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -60,7 +60,7 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
) )
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self, activate_kw=None):
""" """
Adopt new property to movements or deliveries. Adopt new property to movements or deliveries.
""" """
...@@ -73,6 +73,9 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -73,6 +73,9 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
delivery_dict.setdefault(simulation_movement.getDeliveryValue(), delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement) []).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems(): for movement, simulation_movement_list in delivery_dict.iteritems():
if activate_kw is not None:
movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
for solved_property in solved_property_list: for solved_property in solved_property_list:
# XXX hardcoded # XXX hardcoded
if solved_property == 'quantity': if solved_property == 'quantity':
...@@ -84,7 +87,8 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -84,7 +87,8 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
delivery_ratio = quantity / total_quantity delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity delivery_error = total_quantity * delivery_ratio - quantity
simulation_movement.edit(delivery_ratio=delivery_ratio, simulation_movement.edit(delivery_ratio=delivery_ratio,
delivery_error=delivery_error) delivery_error=delivery_error,
activate_kw=activate_kw)
else: else:
# XXX TODO we need to support multiple values for categories or # XXX TODO we need to support multiple values for categories or
# list type property. # list type property.
......
...@@ -63,7 +63,7 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -63,7 +63,7 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
) )
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self, activate_kw=None):
""" """
""" """
configuration_dict = self.getConfigurationPropertyDict() configuration_dict = self.getConfigurationPropertyDict()
...@@ -76,7 +76,8 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -76,7 +76,8 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
delivery_solver = self.portal_solvers.newDeliverySolver( delivery_solver = self.portal_solvers.newDeliverySolver(
configuration_dict['delivery_solver'], simulation_movement_list) configuration_dict['delivery_solver'], simulation_movement_list)
# Update the quantity using delivery solver algorithm # Update the quantity using delivery solver algorithm
split_list = delivery_solver.setTotalQuantity(decision_quantity) split_list = delivery_solver.setTotalQuantity(decision_quantity,
activate_kw=activate_kw)
# Create split movements # Create split movements
for (simulation_movement, split_quantity) in split_list: for (simulation_movement, split_quantity) in split_list:
split_index = 0 split_index = 0
...@@ -91,7 +92,10 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -91,7 +92,10 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
'id':new_id, 'id':new_id,
'delivery':None, 'delivery':None,
'quantity':split_quantity}) 'quantity':split_quantity})
new_movement = applied_rule.newContent(**kw) new_movement = applied_rule.newContent(activate_kw=activate_kw, **kw)
if activate_kw is not None:
new_movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
start_date = configuration_dict.get('start_date', None) start_date = configuration_dict.get('start_date', None)
if start_date is not None: if start_date is not None:
new_movement.recordProperty('start_date') new_movement.recordProperty('start_date')
...@@ -100,6 +104,9 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -100,6 +104,9 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
if stop_date is not None: if stop_date is not None:
new_movement.recordProperty('stop_date') new_movement.recordProperty('stop_date')
new_movement.setStopDate(stop_date) new_movement.setStopDate(stop_date)
# XXX we need to call expand on both simulation_movement and new_movement here?
# simulation_movement.expand(activate_kw=activate_kw)
# new_movement.expand(activate_kw=activate_kw)
# Finish solving # Finish solving
self.succeed() self.succeed()
...@@ -173,7 +173,7 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -173,7 +173,7 @@ class SolverProcess(XMLObject, ActiveProcess):
# ISolver implementation # ISolver implementation
# Solver Process Workflow Interface # Solver Process Workflow Interface
# NOTE: how can we consider that a workflow defines or provides an interface ? # NOTE: how can we consider that a workflow defines or provides an interface ?
def solve(self): def solve(self, activate_kw=None):
""" """
Start solving Start solving
""" """
...@@ -181,7 +181,8 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -181,7 +181,8 @@ class SolverProcess(XMLObject, ActiveProcess):
for solver in self.contentValues(portal_type=self.getPortalObject().getPortalTargetSolverTypeList()): for solver in self.contentValues(portal_type=self.getPortalObject().getPortalTargetSolverTypeList()):
if isTransitionPossible(solver, 'start_solving'): if isTransitionPossible(solver, 'start_solving'):
solver.startSolving() solver.startSolving()
solver.activate(active_process=self).solve() solver.activate(active_process=self, activate_kw=activate_kw).solve(
activate_kw=activate_kw)
# API # API
def isSolverDecisionListConsistent(self): def isSolverDecisionListConsistent(self):
......
...@@ -55,7 +55,7 @@ class TradeModelSolver(AcceptSolver): ...@@ -55,7 +55,7 @@ class TradeModelSolver(AcceptSolver):
zope.interface.implements(interfaces.ISolver,) zope.interface.implements(interfaces.ISolver,)
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self, activate_kw=None):
""" """
Adopt new values to simulation movements, with keeping the original Adopt new values to simulation movements, with keeping the original
one recorded, and then update Trade Model related lines accordingly. one recorded, and then update Trade Model related lines accordingly.
...@@ -93,6 +93,9 @@ class TradeModelSolver(AcceptSolver): ...@@ -93,6 +93,9 @@ class TradeModelSolver(AcceptSolver):
# then expand. # then expand.
for movement, simulation_movement_list in delivery_dict.iteritems(): for movement, simulation_movement_list in delivery_dict.iteritems():
for simulation_movement in simulation_movement_list: for simulation_movement in simulation_movement_list:
if activate_kw is not None:
simulation_movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
value_dict = {} value_dict = {}
for solved_property in solved_property_list: for solved_property in solved_property_list:
new_value = movement.getProperty(solved_property) new_value = movement.getProperty(solved_property)
...@@ -104,12 +107,16 @@ class TradeModelSolver(AcceptSolver): ...@@ -104,12 +107,16 @@ class TradeModelSolver(AcceptSolver):
for property_id, value in value_dict.iteritems(): for property_id, value in value_dict.iteritems():
if not simulation_movement.isPropertyRecorded(property_id): if not simulation_movement.isPropertyRecorded(property_id):
simulation_movement.recordProperty(property_id) simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value) simulation_movement.setMappedProperty(property_id, value,
simulation_movement.expand() activate_kw=activate_kw)
simulation_movement.expand(activate_kw=activate_kw)
# Third, adopt changes on trade model related lines. # Third, adopt changes on trade model related lines.
# XXX non-linear case is not yet supported. # XXX non-linear case is not yet supported.
for movement in trade_model_related_movement_list: for movement in trade_model_related_movement_list:
if activate_kw is not None:
movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
for solved_property in solved_property_list: for solved_property in solved_property_list:
if solved_property == 'quantity': if solved_property == 'quantity':
simulation_movement_list = movement.getDeliveryRelatedValueList() simulation_movement_list = movement.getDeliveryRelatedValueList()
...@@ -121,7 +128,8 @@ class TradeModelSolver(AcceptSolver): ...@@ -121,7 +128,8 @@ class TradeModelSolver(AcceptSolver):
delivery_ratio = quantity / total_quantity delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity delivery_error = total_quantity * delivery_ratio - quantity
simulation_movement.edit(delivery_ratio=delivery_ratio, simulation_movement.edit(delivery_ratio=delivery_ratio,
delivery_error=delivery_error) delivery_error=delivery_error,
activate_kw=activate_kw)
else: else:
# XXX TODO we need to support multiple values for categories or # XXX TODO we need to support multiple values for categories or
# list type property. # list type property.
......
...@@ -56,7 +56,7 @@ class UnifySolver(AcceptSolver): ...@@ -56,7 +56,7 @@ class UnifySolver(AcceptSolver):
zope.interface.implements(interfaces.ISolver,) zope.interface.implements(interfaces.ISolver,)
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self, activate_kw=None):
""" """
Adopt new property to simulation movements, with keeping the Adopt new property to simulation movements, with keeping the
original one recorded. original one recorded.
...@@ -72,15 +72,21 @@ class UnifySolver(AcceptSolver): ...@@ -72,15 +72,21 @@ class UnifySolver(AcceptSolver):
delivery_dict.setdefault(simulation_movement.getDeliveryValue(), delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement) []).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems(): for movement, simulation_movement_list in delivery_dict.iteritems():
if activate_kw is not None:
movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
configuration_dict = self.getConfigurationPropertyDict() configuration_dict = self.getConfigurationPropertyDict()
new_value = configuration_dict.get('value') new_value = configuration_dict.get('value')
movement.setProperty(solved_property, new_value) movement.setProperty(solved_property, new_value)
for simulation_movement in simulation_movement_list: for simulation_movement in simulation_movement_list:
if activate_kw is not None:
simulation_movement.setDefaultActivateParameters(
activate_kw=activate_kw, **activate_kw)
value_dict = {solved_property:new_value} value_dict = {solved_property:new_value}
for property_id, value in value_dict.iteritems(): for property_id, value in value_dict.iteritems():
if not simulation_movement.isPropertyRecorded(property_id): if not simulation_movement.isPropertyRecorded(property_id):
simulation_movement.recordProperty(property_id) simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value) simulation_movement.setMappedProperty(property_id, value)
simulation_movement.expand() simulation_movement.expand(activate_kw=activate_kw)
# Finish solving # Finish solving
self.succeed() self.succeed()
...@@ -46,7 +46,7 @@ class ISolver(Interface): ...@@ -46,7 +46,7 @@ class ISolver(Interface):
- find a way to define at which level to solve divergences - find a way to define at which level to solve divergences
(ex. line, delivery) (ex. line, delivery)
""" """
def solve(): def solve(activate_kw=None):
""" """
Start the solving process (and trigger the workflow method Start the solving process (and trigger the workflow method
in solver_process_workflow). At the end the solving process, in solver_process_workflow). At the end the solving process,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment