Skip to content

Commit

Permalink
adding support for multiple fsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed Mar 7, 2021
1 parent f7da72d commit 8c26240
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
7 changes: 4 additions & 3 deletions FrmMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def cmdCompact_clicked():
frmObj.table_Equip.sig_fs_list_updated.connect(frmObj.table_FS_Cost.reload_list)
frmObj.treeFS_Secondary.sig_fsl_invalidated.connect(self.treeFS_Secondary_sig_fsl_invalidated)
frmObj.treeFS_Secondary.sig_sec_gear_changed.connect(frmObj.table_genome.gear_invalidated)
frmObj.table_genome.sig_item_clicked.connect(frmObj.table_FS_Cost_Secondary.cmdFSRefresh_clicked)

frmObj.table_Strat_FS.setSortingEnabled(True)
frmObj.table_Strat_Equip.setSortingEnabled(True)
Expand All @@ -317,17 +318,17 @@ def cmdCompact_clicked():
def treeFS_Secondary_sig_fsl_invalidated(self):
#self.ui.table_genome.fls_invalidated()
self.invalidate_equipment()
self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()
#self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()

def table_FS_Cost_sig_fs_calculated(self):
self.ui.table_genome.fs_list_updated()
self.invalidate_equipment()
self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()
#self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()

def table_genome_sig_selected_genome_changed(self):
#self.model.invalidate_secondary_fs()
self.invalidate_equipment()
self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()
#self.ui.table_FS_Cost_Secondary.cmdFSRefresh_clicked()
self.ui.treeFS_Secondary.refresh_strat()

def evolve_thread_created(self, thrd):
Expand Down
2 changes: 2 additions & 0 deletions Widgets/TreeEquipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from BDO_Enhancement_Tool.model import SettingsException, Enhance_model, Invalid_FS_Parameters
from BDO_Enhancement_Tool.qt_UI_Common import pix, STR_PIC_CRON, STR_CALC_PIC
from BDO_Enhancement_Tool.dlgGearWindow import GearWindow
from BDO_Enhancement_Tool.utilities import fmt_traceback

from .Abstract_Gear_Tree import AbstractGearTree, HEADER_NAME, HEADER_GEAR_TYPE, HEADER_BASE_ITEM_COST, HEADER_TARGET

Expand Down Expand Up @@ -67,6 +68,7 @@ def cmdEquipCost_clicked(self):
model.calc_equip_costs(gear=self.invalidated_gear)
self.invalidated_gear = set()
except ValueError as f:
print(fmt_traceback(f.__traceback__))
frmMain.sig_show_message.emit(frmMain.WARNING, str(f))
return
except Invalid_FS_Parameters as e:
Expand Down
44 changes: 36 additions & 8 deletions Widgets/tableGenome.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
HEADER_NAME = 'Name'
HEADER_GENOME = 'Genome'
HEADER_FITNESS = 'Fitness'
HEADER_NUM_FS = '# FS'


class DlgEvolveSettings(QDialog):
Expand Down Expand Up @@ -133,7 +134,7 @@ def __init__(self, model:Enhance_model, *args, fsl=None, checked=True, **kwargs)
self.checked = checked
super(EvolveSolutionWidget, self).__init__(model, *args, **kwargs)

def set_gear(self, gear:Gear):
def set_gear(self, gear: Gear):
if gear is None:
self.invalidate_plot()
self.fsl.secondary_gear = gear
Expand All @@ -145,6 +146,12 @@ def update_data(self):
self.update_gw()
self.update_genome()

def update_num_fs(self):
tree = self.treeWidget()
idx_NUM_FS = tree.get_header_index(HEADER_NUM_FS)
with QBlockSig(self.treeWidget()):
self.setText(idx_NUM_FS, str(self.fsl.num_fs))

def update_gw(self):
gear = self.fsl.secondary_gear
tree = self.treeWidget()
Expand All @@ -168,7 +175,7 @@ def update_genome(self):
with QBlockSig(self.treeWidget()):
self.setText(idx_GENOME, str(self.fsl.get_gnome()))

def set_fsl(self, fsl:FailStackList):
def set_fsl(self, fsl: FailStackList):
self.fsl = fsl
self.set_gear(fsl.secondary_gear)
self.set_gnome(fsl.get_gnome())
Expand Down Expand Up @@ -211,8 +218,9 @@ def plot(self):
graph = parent.graph
fsl:FailStackList = self.fsl
model = self.model
self.fsl.set_primary_data(model.optimal_fs_items, model.primary_fs_cost, model.primary_cum_fs_cost)
fsl.evaluate_map()
if not self.fsl.has_ran():
self.fsl.set_primary_data(model.optimal_fs_items, model.primary_fs_cost, model.primary_cum_fs_cost)
fsl.evaluate_map()
self.plt = graph.plot(numpy.arange(1, len(fsl.fs_cost) + 1), fsl.fs_cum_cost, pen=mkPen(parent.color))
self.invalidated = False

Expand All @@ -222,7 +230,7 @@ def check_error(self):
self.setForeground(idx_GENOME, QColor(Qt.black))
if self.fsl.validate():
settings = self.model.settings
if self.fsl in settings[settings.P_GENOME_FS]:
if self.fsl in settings[settings.P_GENOME_FS] and not self.fsl.has_ran():
self.model.invalidate_secondary_fs()
tree.sig_selected_genome_changed.emit()
idx_GENOME = self.treeWidget().get_header_index(HEADER_GENOME)
Expand Down Expand Up @@ -445,7 +453,7 @@ class TableGenome(QTreeWidget, AbstractTable):
sig_thread_created = pyqtSignal(object, name='sig_thread_created')
sig_thread_destroyed = pyqtSignal(object, name='sig_thread_destroyed')
sig_selected_genome_changed = pyqtSignal(name='sig_selected_genome_changed')
sig_item_clicked = pyqtSignal(name='sig_item_clicked')
sig_item_clicked = pyqtSignal(object, name='sig_item_clicked')
HEADERS = [HEADER_NAME, HEADER_GENOME, HEADER_FITNESS]

def __init__(self, *args, **kwargs):
Expand All @@ -460,7 +468,10 @@ def __init__(self, *args, **kwargs):

def clicked_cb(self, index):
twi = self.itemFromIndex(index)

if isinstance(twi, EvolveSolutionWidget):
fsl = twi.fsl
if fsl.validate():
self.sig_item_clicked.emit(fsl)

def mouseReleaseEvent(self, a0) -> None:
super(TableGenome, self).mouseReleaseEvent(a0)
Expand Down Expand Up @@ -608,6 +619,7 @@ def set_common(self, model: Enhance_model, frmMain: lbl_color_MainWindow):
self.clear()

fsl_l = settings[settings.P_FSL_L]
checked = set()
for name, color, children in fsl_l:
itm = UserGroupTreeWidgetItem(model, self.graph, self, [''] * self.columnCount(), color=RGBA_to_Qcolor(color),
grp_name=name)
Expand All @@ -623,7 +635,23 @@ def set_common(self, model: Enhance_model, frmMain: lbl_color_MainWindow):
fsl = settings[settings.P_GENOME_FS][child_obj]
self.chosen_twis.append(itmc)
itmc.setIcon(0, pix.get_icon(STR_CHECK_PIC))
checked.add(fsl)
itmc.set_fsl(fsl)
itmc.update_data()
itm.setExpanded(True)

unaccount = [x for x in settings[settings.P_GENOME_FS] if x not in checked]
if len(unaccount) > 0:
itm = UserGroupTreeWidgetItem(model, self.graph, self, [''] * self.columnCount(),
color=QColor(Qt.red),
grp_name='Current Setting')
self.addTopLevelItem(itm)
for fsl in unaccount:
itmc = GenomeTreeWidgetItem(model, itm, [''] * self.columnCount(), checked=False)
itm.addChild(itmc)
self.chosen_twis.append(itmc)
itmc.setIcon(0, pix.get_icon(STR_CHECK_PIC))
itmc.set_fsl(fsl)
itm.setExpanded(True)
itmc.update_data()
itm.setExpanded(True)

2 changes: 1 addition & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def enhance_cost_simp(self, cum_fs, material_cost, fail_repair_cost_nom):

def enhance_cost(self, cum_fs):
if not self.costs_need_update:
return
return self.cost_vec
settings = self.settings
num_fs = settings[EnhanceSettings.P_NUM_FS]+1
p_num_f_map = self.gear_type.p_num_atmpt_map
Expand Down
32 changes: 14 additions & 18 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self):
class SettingsException(Exception):
def __init__(self, msg, embedded):
super(SettingsException, self).__init__(msg)
self.embedded:Exception = embedded
self.embedded: Exception = embedded

def __str__(self):
this_str = super(SettingsException, self).__str__()
Expand Down Expand Up @@ -212,9 +212,7 @@ def __init__(self, settings, secondary:Union[Gear,None], optimal_primary_list: U
self.fs_cost = None
self.fs_cum_cost = None

self.fl_safety = True
self.fl_cost = True
self.fl_cum_cost = True
self.needs_update = True

if num_fs is None:
num_fs = settings[settings.P_NUM_FS]
Expand All @@ -239,21 +237,21 @@ def set_primary_data(self, optimal_primary_list: List[Gear], optimal_cost, cum_c

def set_gear_list(self, optimal_primary_list: List[Gear]):
if optimal_primary_list is not None:
self.fl_safety = True
self.needs_update = True
if self.num_fs < len(optimal_primary_list) - 1:
optimal_primary_list = optimal_primary_list[:self.num_fs+1]
self.gear_list = optimal_primary_list.copy()

def set_fs_cost(self, optimal_cost):
if optimal_cost is not None:
self.fl_cost = True
self.needs_update = True
if len(optimal_cost) <= self.num_fs:
self.num_fs = len(optimal_cost) - 1
self.fs_cost = numpy.copy(optimal_cost[:self.num_fs+1])

def set_fs_cum_cost(self, cum_cost):
if cum_cost is not None:
self.fl_cum_cost = True
self.needs_update = True
if len(cum_cost) <= self.num_fs:
self.num_fs = len(cum_cost) - 1
self.fs_cum_cost = numpy.copy(cum_cost[:self.num_fs+1])
Expand Down Expand Up @@ -291,16 +289,13 @@ def generate_secondary_map(self, starting_pos):
this_gl_idx += 1

def has_ran(self):
return not (self.fl_cost and self.fl_cum_cost and self.fl_safety)
return not self.needs_update

def evaluate_map(self, varbose=False):
if self.starting_pos is None:
raise Exception()
if self.has_ran():
raise Exception('Can not evaluate map twice without resetting primary data')
self.fl_cost = False
self.fl_cum_cost = False
self.fl_safety = False
starting_pos = self.starting_pos
settings = self.settings
num_fs = self.num_fs + 1
Expand Down Expand Up @@ -506,6 +501,7 @@ def get_gear(M, gear_idx):
fs_cost[offset] = cost_f
fs_cum_cost[offset] = self.fs_cum_cost[offset - 1] + cost_f
self.factor_pripen(pripen_cost, num_fs - starting_pos)
self.needs_update = False
return
gear_list[offset] = s_g
fs_cost[offset] = cost_f
Expand Down Expand Up @@ -557,6 +553,7 @@ def get_gear(M, gear_idx):
prev_cost_per_succ_just_f = count_cost_overstack_just_f
self.avg_cost.append(prev_cost_per_succ)
self.factor_pripen(pripen_cost, num_fs - starting_pos)
self.needs_update = False

def get_pri_cost(self):
settings = self.settings
Expand Down Expand Up @@ -647,6 +644,7 @@ def get_gnome(self):
def set_gnome(self, gnome):
self.starting_pos = gnome[0]
self.secondary_map = (*gnome[1:], 100000)
self.needs_update = True

def validate(self):
#if self.fs_cost is None or self.gear_list is None or self.fs_cum_cost is None:
Expand Down Expand Up @@ -1419,12 +1417,14 @@ def calcFS(self):

fs_cost = numpy.array(fs_cost)
cum_fs_cost = numpy.array(cum_fs_cost)
fs_cost.setflags(write=False)
cum_fs_cost.setflags(write=False)
self.primary_fs_gear = fs_items
self.primary_fs_cost = fs_cost
self.primary_cum_fs_cost = cum_fs_cost
self.optimal_fs_items = fs_items
self.fs_cost = fs_cost
self.cum_fs_cost = cum_fs_cost
self.fs_cost = numpy.copy(fs_cost)
self.cum_fs_cost = numpy.copy(cum_fs_cost)
self.cum_fs_probs = cum_fs_probs
self.fs_probs = fs_probs
self.fs_needs_update = False
Expand All @@ -1438,11 +1438,7 @@ def calcFS(self):
for i in range(0, bts-1): # PRI is at bts-1
cum_cost += min(csv[i])
sfsg.pri_cost = cum_cost
try:
self.calc_fs_secondary()
finally:
fs_cost.setflags(write=False)
cum_fs_cost.setflags(write=False)
self.calc_fs_secondary()

def calc_fs_secondary(self):
self.fs_needs_update = False
Expand Down

0 comments on commit 8c26240

Please sign in to comment.