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):
original one recorded.
"""
configuration_dict = self.getConfigurationPropertyDict()
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list',
portal_type.getTestedPropertyList())
for movement in self.getDeliveryValueList():
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:
value_dict = {}
for solved_property in solved_property_list:
new_value = movement.getProperty(solved_property)
# XXX hard coded
if solved_property == 'quantity':
new_quantity = new_value * simulation_movement.getDeliveryRatio()
value_dict.update({'quantity':new_quantity})
else:
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()
solved_property_list = configuration_dict.get('tested_property_list', None)
if solved_property_list is None:
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = portal_type.getTestedPropertyList()
for simulation_movement in self.getDeliveryValueList():
movement = simulation_movement.getDeliveryValue()
value_dict = {}
for solved_property in solved_property_list:
new_value = movement.getProperty(solved_property)
# XXX hard coded
if solved_property == 'quantity':
new_quantity = new_value * simulation_movement.getDeliveryRatio()
value_dict.update({'quantity':new_quantity})
else:
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
self.succeed()
......@@ -68,14 +68,18 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list',
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:
# XXX hardcoded
if solved_property == 'quantity':
total_quantity = sum(
[x.getQuantity() for x in movement.getDeliveryRelatedValueList()])
movement.setQuantity(total_quantity)
for simulation_movement in movement.getDeliveryRelatedValueList():
for simulation_movement in simulation_movement_list:
quantity = simulation_movement.getQuantity()
delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity
......
......@@ -65,11 +65,14 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
# ISolver Implementation
def solve(self):
"""
"""
for delivery_line in self.getDeliveryValueList():
decision_quantity = delivery_line.getQuantity()
simulation_movement_list = delivery_line.getDeliveryRelatedValueList()
configuration_dict = self.getConfigurationPropertyDict()
"""
configuration_dict = self.getConfigurationPropertyDict()
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():
decision_quantity = movement.getQuantity()
delivery_solver = self.portal_solvers.newDeliverySolver(
configuration_dict['delivery_solver'], simulation_movement_list)
# Update the quantity using delivery solver algorithm
......
......@@ -83,7 +83,7 @@ class SolverProcess(XMLObject, ActiveProcess):
movement_dict = {}
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
# and which parameters with
#
......@@ -230,7 +230,7 @@ class SolverProcess(XMLObject, ActiveProcess):
application_list.sort()
solver_decision_key = (divergence_tester.getRelativeUrl(), tuple(application_list))
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
# grouping
......@@ -259,12 +259,11 @@ class SolverProcess(XMLObject, ActiveProcess):
# Process, but ideally, the relation should be created when a
# Target Solver processes, not when a Solver Decision is
# created.
# for movement in movement_dict.keys():
# for simulation_movement in movement.getDeliveryRelatedValueList():
# solver_list = simulation_movement.getSolverValueList()
# if self not in solver_list:
# simulation_movement.setSolverValueList(
# solver_list + [self])
# for simulation_movement in movement_dict.keys():
# solver_list = simulation_movement.getSolverValueList()
# if self not in solver_list:
# simulation_movement.setSolverValueList(
# solver_list + [self])
# XXX what should we do for non-matched existing solver decisions?
# do we need to cancel them by using an appropriate workflow?
......
......@@ -64,15 +64,18 @@ class TradeModelSolver(AcceptSolver):
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list',
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.
solved_movement_list = self.getDeliveryValueList()
delivery_list = []
for solved_movement in solved_movement_list:
delivery = solved_movement.getDeliveryValue()
if delivery not in delivery_list:
delivery_list.append(delivery)
all_movement_list = sum([x.getMovementList() for x in delivery_list], [])
delivery_set = set()
solved_movement_list = delivery_dict.iterkeys()
for movement in solved_movement_list:
delivery = movement.getRootDeliveryValue()
delivery_set.add(delivery)
all_movement_list = sum([x.getMovementList() for x in delivery_set], [])
# First, separate movements into invoice lines and trade model
# related lines.
......@@ -88,8 +91,8 @@ class TradeModelSolver(AcceptSolver):
# Second, apply changes on invoice lines to simulation movements,
# then expand.
for movement in solved_movement_list:
for simulation_movement in movement.getDeliveryRelatedValueList():
for movement, simulation_movement_list in delivery_dict.iteritems():
for simulation_movement in simulation_movement_list:
value_dict = {}
for solved_property in solved_property_list:
new_value = movement.getProperty(solved_property)
......
......@@ -67,17 +67,14 @@ class UnifySolver(AcceptSolver):
portal_type.getTestedPropertyList())
# XXX it does not support multiple tested properties.
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()
new_value = configuration_dict.get('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:
value_dict = {solved_property:new_value}
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