Commit 0acf8bfe authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

store a list of simulation movements to be solved instead of delivery...

store a list of simulation movements to be solved instead of delivery movements in a Solver Decision document, that is more efficient and consistent with the way to find appropriate target solvers whose predicate's context is a simulation movement.
XXX now using 'delivery' category to store simulation movements does not sound good.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36616 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6f2ec9a1
...@@ -64,31 +64,25 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -64,31 +64,25 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
original one recorded. original one recorded.
""" """
configuration_dict = self.getConfigurationPropertyDict() configuration_dict = self.getConfigurationPropertyDict()
portal_type = self.getPortalObject().portal_types.getTypeInfo(self) solved_property_list = configuration_dict.get('tested_property_list', None)
solved_property_list = configuration_dict.get('tested_property_list', if solved_property_list is None:
portal_type.getTestedPropertyList()) portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
for movement in self.getDeliveryValueList(): solved_property_list = portal_type.getTestedPropertyList()
simulation_movement_list = movement.getDeliveryRelatedValueList() for simulation_movement in self.getDeliveryValueList():
# if movement here is a delivery, we need to find simulation movement = simulation_movement.getDeliveryValue()
# movements by its movements. value_dict = {}
if len(simulation_movement_list) == 0: for solved_property in solved_property_list:
simulation_movement_list = sum( new_value = movement.getProperty(solved_property)
[x.getDeliveryRelatedValueList() \ # XXX hard coded
for x in self.getDeliveryValue().getMovementList()], []) if solved_property == 'quantity':
for simulation_movement in simulation_movement_list: new_quantity = new_value * simulation_movement.getDeliveryRatio()
value_dict = {} value_dict.update({'quantity':new_quantity})
for solved_property in solved_property_list: else:
new_value = movement.getProperty(solved_property) value_dict.update({solved_property:new_value})
# XXX hard coded for property_id, value in value_dict.iteritems():
if solved_property == 'quantity': if not simulation_movement.isPropertyRecorded(property_id):
new_quantity = new_value * simulation_movement.getDeliveryRatio() simulation_movement.recordProperty(property_id)
value_dict.update({'quantity':new_quantity}) simulation_movement.setMappedProperty(property_id, value)
else: simulation_movement.expand()
value_dict.update({solved_property:new_value})
for property_id, value in value_dict.iteritems():
if not simulation_movement.isPropertyRecorded(property_id):
simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value)
simulation_movement.expand()
# Finish solving # Finish solving
self.succeed() self.succeed()
...@@ -68,14 +68,18 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -68,14 +68,18 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
portal_type = self.getPortalObject().portal_types.getTypeInfo(self) portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list', solved_property_list = configuration_dict.get('tested_property_list',
portal_type.getTestedPropertyList()) portal_type.getTestedPropertyList())
for movement in self.getDeliveryValueList(): delivery_dict = {}
for simulation_movement in self.getDeliveryValueList():
delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems():
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':
total_quantity = sum( total_quantity = sum(
[x.getQuantity() for x in movement.getDeliveryRelatedValueList()]) [x.getQuantity() for x in movement.getDeliveryRelatedValueList()])
movement.setQuantity(total_quantity) movement.setQuantity(total_quantity)
for simulation_movement in movement.getDeliveryRelatedValueList(): for simulation_movement in simulation_movement_list:
quantity = simulation_movement.getQuantity() quantity = simulation_movement.getQuantity()
delivery_ratio = quantity / total_quantity delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity delivery_error = total_quantity * delivery_ratio - quantity
......
...@@ -65,11 +65,14 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -65,11 +65,14 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
# ISolver Implementation # ISolver Implementation
def solve(self): def solve(self):
""" """
""" """
for delivery_line in self.getDeliveryValueList(): configuration_dict = self.getConfigurationPropertyDict()
decision_quantity = delivery_line.getQuantity() delivery_dict = {}
simulation_movement_list = delivery_line.getDeliveryRelatedValueList() for simulation_movement in self.getDeliveryValueList():
configuration_dict = self.getConfigurationPropertyDict() delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems():
decision_quantity = movement.getQuantity()
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
......
...@@ -83,7 +83,7 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -83,7 +83,7 @@ class SolverProcess(XMLObject, ActiveProcess):
movement_dict = {} movement_dict = {}
message_list = [] message_list = []
# First create a mapping between delivery movements and solvers # First create a mapping between simulation movements and solvers
# in order to know for each movements which solvers are needed # in order to know for each movements which solvers are needed
# and which parameters with # and which parameters with
# #
...@@ -230,7 +230,7 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -230,7 +230,7 @@ class SolverProcess(XMLObject, ActiveProcess):
application_list.sort() application_list.sort()
solver_decision_key = (divergence_tester.getRelativeUrl(), tuple(application_list)) solver_decision_key = (divergence_tester.getRelativeUrl(), tuple(application_list))
movement_dict = solver_decision_dict.setdefault(solver_decision_key, {}) movement_dict = solver_decision_dict.setdefault(solver_decision_key, {})
movement_dict[movement] = None movement_dict[simulation_movement] = None
# Now build the solver decision instances based on the previous # Now build the solver decision instances based on the previous
# grouping # grouping
...@@ -259,12 +259,11 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -259,12 +259,11 @@ class SolverProcess(XMLObject, ActiveProcess):
# Process, but ideally, the relation should be created when a # Process, but ideally, the relation should be created when a
# Target Solver processes, not when a Solver Decision is # Target Solver processes, not when a Solver Decision is
# created. # created.
# for movement in movement_dict.keys(): # for simulation_movement in movement_dict.keys():
# for simulation_movement in movement.getDeliveryRelatedValueList(): # solver_list = simulation_movement.getSolverValueList()
# solver_list = simulation_movement.getSolverValueList() # if self not in solver_list:
# if self not in solver_list: # simulation_movement.setSolverValueList(
# simulation_movement.setSolverValueList( # solver_list + [self])
# solver_list + [self])
# XXX what should we do for non-matched existing solver decisions? # XXX what should we do for non-matched existing solver decisions?
# do we need to cancel them by using an appropriate workflow? # do we need to cancel them by using an appropriate workflow?
......
...@@ -64,15 +64,18 @@ class TradeModelSolver(AcceptSolver): ...@@ -64,15 +64,18 @@ class TradeModelSolver(AcceptSolver):
portal_type = self.getPortalObject().portal_types.getTypeInfo(self) portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list', solved_property_list = configuration_dict.get('tested_property_list',
portal_type.getTestedPropertyList()) portal_type.getTestedPropertyList())
delivery_dict = {}
for simulation_movement in self.getDeliveryValueList():
delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement)
# Here, items of delivery_list should be movements, not deliveries. # Here, items of delivery_list should be movements, not deliveries.
solved_movement_list = self.getDeliveryValueList() delivery_set = set()
delivery_list = [] solved_movement_list = delivery_dict.iterkeys()
for solved_movement in solved_movement_list: for movement in solved_movement_list:
delivery = solved_movement.getDeliveryValue() delivery = movement.getRootDeliveryValue()
if delivery not in delivery_list: delivery_set.add(delivery)
delivery_list.append(delivery) all_movement_list = sum([x.getMovementList() for x in delivery_set], [])
all_movement_list = sum([x.getMovementList() for x in delivery_list], [])
# First, separate movements into invoice lines and trade model # First, separate movements into invoice lines and trade model
# related lines. # related lines.
...@@ -88,8 +91,8 @@ class TradeModelSolver(AcceptSolver): ...@@ -88,8 +91,8 @@ class TradeModelSolver(AcceptSolver):
# Second, apply changes on invoice lines to simulation movements, # Second, apply changes on invoice lines to simulation movements,
# then expand. # then expand.
for movement in solved_movement_list: for movement, simulation_movement_list in delivery_dict.iteritems():
for simulation_movement in movement.getDeliveryRelatedValueList(): for simulation_movement in simulation_movement_list:
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)
......
...@@ -67,17 +67,14 @@ class UnifySolver(AcceptSolver): ...@@ -67,17 +67,14 @@ class UnifySolver(AcceptSolver):
portal_type.getTestedPropertyList()) portal_type.getTestedPropertyList())
# XXX it does not support multiple tested properties. # XXX it does not support multiple tested properties.
solved_property = solved_property_list[0] solved_property = solved_property_list[0]
for movement in self.getDeliveryValueList(): delivery_dict = {}
for simulation_movement in self.getDeliveryValueList():
delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
[]).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems():
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)
simulation_movement_list = movement.getDeliveryRelatedValueList()
# if movement here is a delivery, we need to find simulation
# movements by its movements.
if len(simulation_movement_list) == 0:
simulation_movement_list = sum(
[x.getDeliveryRelatedValueList() \
for x in self.getDeliveryValue().getMovementList()], [])
for simulation_movement in simulation_movement_list: for simulation_movement in simulation_movement_list:
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():
......
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