Extract code to choose among matched lines while loading UL.

This commit refs #12803
This commit is contained in:
Sergio Morillo 2020-04-29 17:39:49 +02:00
parent 650625fa99
commit 2e16727778
1 changed files with 16 additions and 10 deletions

26
load.py
View File

@ -459,18 +459,11 @@ class LoadOrder(metaclass=PoolMeta):
matched_lines = lines
# check overload line qty
line = None
for _line in matched_lines:
order_lines.setdefault(_line.id,
_line.ul_quantity - len(_line.unit_loads))
if order_lines[_line.id] > 0:
line = _line
break
line = self._choose_matched_line(matched_lines, order_lines,
unit_load)
if line:
order_lines[line.id] -= 1
# load UL
unit_load.load_line = _line
unit_load.load_line = line
elif unit_load not in failed_uls:
self.raise_user_error('ul_overload', self.rec_name)
@ -480,6 +473,19 @@ class LoadOrder(metaclass=PoolMeta):
UL.save(unit_loads)
def _choose_matched_line(self, lines, values, unit_load):
line = None
for _line in lines:
if _line.id not in values:
values.setdefault(_line.id, set(
ul for ul in _line.unit_loads))
if _line.ul_quantity - len(values[_line.id]) > 0:
line = _line
break
if line:
values[line.id].add(unit_load)
return line
def check_origin_restrict(self, unit_load, origin_restrict,
origin_restrict_warn):
lines = []