условно рабочий генератор доменов (без задачи)
This commit is contained in:
parent
a57ab8e9bd
commit
5621cc78e8
4 changed files with 96 additions and 72 deletions
Binary file not shown.
Binary file not shown.
|
@ -29,7 +29,7 @@
|
|||
(endmill_is_ready)
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
(:durative-action PartDesignExample_Profile_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 157)
|
||||
:condition (and
|
||||
|
@ -38,7 +38,7 @@
|
|||
:effect (and
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
(:durative-action PartDesignExample_Pocket3D_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 170)
|
||||
:condition (and
|
||||
|
@ -47,36 +47,9 @@
|
|||
:effect (and
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
(:durative-action PartDesignExample_MillFace_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 78)
|
||||
:condition (and
|
||||
(endmill_is_ready)
|
||||
)
|
||||
:effect (and
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 157)
|
||||
:condition (and
|
||||
(endmill_is_ready)
|
||||
)
|
||||
:effect (and
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 170)
|
||||
:condition (and
|
||||
(endmill_is_ready)
|
||||
)
|
||||
:effect (and
|
||||
)
|
||||
)
|
||||
(:durative-action PartDesignExample_TC: Default Tool
|
||||
:parameters ( )
|
||||
:duration ( = ?duration 78)
|
||||
:duration ( = ?duration 79)
|
||||
:condition (and
|
||||
(endmill_is_ready)
|
||||
)
|
||||
|
|
|
@ -4,8 +4,7 @@ import FreeCADGui as Gui
|
|||
import json
|
||||
|
||||
#1. Экспорт фрикадовских операций
|
||||
doc = App.ActiveDocument
|
||||
file_path = doc.FileName
|
||||
|
||||
|
||||
printer = '/home/mark-voltov/GitProjects/framework/cg/freecad/Frames/pddl/Printer.FCStd'
|
||||
endmill = '/home/mark-voltov/GitProjects/framework/cg/freecad/Frames/pddl/MillingMachine.FCStd'
|
||||
|
@ -26,7 +25,7 @@ def pathCheck(part):
|
|||
checker = True
|
||||
return checker
|
||||
|
||||
print(pathCheck(part))
|
||||
|
||||
|
||||
operations_data = []
|
||||
|
||||
|
@ -62,20 +61,12 @@ def operationsInfoCollecting(part):
|
|||
print('Операции не были обнаружены')
|
||||
|
||||
return operations_data
|
||||
operations_data = operationsInfoCollecting(part)
|
||||
print(operations_data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Словарь для группировки операций по станкам
|
||||
machines_operations = {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def toolOperationCollector(tool):
|
||||
|
@ -92,29 +83,31 @@ def toolOperationCollector(tool):
|
|||
})
|
||||
return tool_operations
|
||||
|
||||
print(toolOperationCollector(tool))
|
||||
|
||||
def operationGenerator(tool, operations_data):
|
||||
|
||||
tool_operations = toolOperationCollector(tool)
|
||||
|
||||
|
||||
#отсеиваем все действия
|
||||
pddl_actions = []
|
||||
for part_operation in operations_data:
|
||||
for tool_operation in tool_operations:
|
||||
if tool_operation['Label'] == part_operation['Tool']:
|
||||
pddl_actions.append({'Label': part_operation['Part_label'] + '_' + tool_operation['Label'],
|
||||
pddl_actions.append({'Label': part_operation['Part_label'] + '_' + part_operation['Operation_name'] + '_' + tool_operation['Label'],
|
||||
'Partname': part_operation['Part_label'],
|
||||
'Conditions': tool_operation['Conditions'],
|
||||
'Duration': part_operation['Duration'],
|
||||
'Effects': tool_operation['Effects'],
|
||||
'Parameters': tool_operation['Parameters'],
|
||||
'Type': tool_operation['Type']})
|
||||
'Type': tool_operation['Type'],
|
||||
'Tool': tool_operation['Label']
|
||||
})
|
||||
#здесь у нас появился список операций применительно к одному станку
|
||||
#выполнив эту функцию для каждого станка, получим кучу операций для всего
|
||||
return pddl_actions
|
||||
|
||||
print(operationGenerator(tool, operations_data))
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -162,12 +155,12 @@ def time_in_sec(time_str):
|
|||
|
||||
#основной документ здесь - станок. Нужно поместить файл домена в папку с оборудованием
|
||||
|
||||
def export_to_file(tool, pddl_entities_list):
|
||||
# filename = App.ActiveDocument.Name
|
||||
def domain_export(tool, pddl_entities_list):
|
||||
|
||||
file_path = endmill.rsplit("/", 1)[0] + '/domain.pddl'
|
||||
# file_path = tool.FileName.rsplit("/", 1)[0] + 'domain.pddl'
|
||||
|
||||
filename = 'fabrication'
|
||||
# doc = App.ActiveDocument
|
||||
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
f.write('(define (domain '+ filename +')\n \n')
|
||||
|
@ -176,8 +169,7 @@ def export_to_file(tool, pddl_entities_list):
|
|||
# Типы обьектов
|
||||
#выбираем словари, которые соответствуют типу types
|
||||
types_list = [d for d in pddl_entities_list if d.get("Type") == 'Types']
|
||||
print('типы')
|
||||
print(types_list)
|
||||
|
||||
|
||||
f.write('(:types \n')
|
||||
|
||||
|
@ -192,8 +184,7 @@ def export_to_file(tool, pddl_entities_list):
|
|||
#выбираем словари, соответствующие предикатам
|
||||
f.write(' (:predicates\n')
|
||||
predicates_list = [d for d in pddl_entities_list if d.get("Type") == 'Predicate']
|
||||
print('преды')
|
||||
print(predicates_list)
|
||||
|
||||
for obj in predicates_list:
|
||||
|
||||
f.write(' ('+ obj['Label'])
|
||||
|
@ -210,8 +201,7 @@ def export_to_file(tool, pddl_entities_list):
|
|||
#выбираем словари, соответствующие действиям
|
||||
|
||||
actions_list = [d for d in pddl_entities_list if d.get("Type") == 'Action']
|
||||
print('акции')
|
||||
print(actions_list)
|
||||
|
||||
for obj in actions_list:
|
||||
|
||||
|
||||
|
@ -231,7 +221,7 @@ def export_to_file(tool, pddl_entities_list):
|
|||
|
||||
for effect in obj['Effects']:
|
||||
f.write(' (' + effect + ') \n')
|
||||
# f.write(' ')
|
||||
|
||||
f.write(')\n')
|
||||
|
||||
f.write(' )\n')
|
||||
|
@ -240,8 +230,7 @@ def export_to_file(tool, pddl_entities_list):
|
|||
#выбираем словари, соответствующие действиям
|
||||
|
||||
durative_actions_list = [d for d in pddl_entities_list if d.get("Type") == 'DurativeAction']
|
||||
print('дакции')
|
||||
print(durative_actions_list)
|
||||
|
||||
for obj in durative_actions_list:
|
||||
f.write('(:durative-action ' + obj['Label'] + '\n')
|
||||
f.write(' :parameters (')
|
||||
|
@ -253,15 +242,13 @@ def export_to_file(tool, pddl_entities_list):
|
|||
|
||||
for condition in obj['Conditions']:
|
||||
f.write(' (' + condition + ') \n')
|
||||
# f.write(') ')
|
||||
# f.write(')\n')
|
||||
|
||||
f.write(' )\n')
|
||||
|
||||
f.write(' :effect (and \n')
|
||||
|
||||
for effect in obj['Effects']:
|
||||
f.write(' (' + effect + ') \n')
|
||||
# f.write(' ')
|
||||
f.write(')\n')
|
||||
|
||||
f.write(' )\n')
|
||||
|
@ -271,22 +258,86 @@ def export_to_file(tool, pddl_entities_list):
|
|||
f.write(' )\n')
|
||||
|
||||
tool_non_operations = []
|
||||
tool_operations = []
|
||||
|
||||
|
||||
operations_data = operationsInfoCollecting(part)
|
||||
|
||||
# tool = App.open(toolslist[1])
|
||||
|
||||
|
||||
pddl_actions = operationGenerator(tool, operations_data)
|
||||
|
||||
tool_non_actions = collectingNonActions(tool)
|
||||
print(tool_non_actions)
|
||||
# tool_operations = pddl_actions #вот здесь должны быть уже обработанные данные, а не полуфабрикаты, как сейчас
|
||||
pddl_non_actions = collectingNonActions(tool)
|
||||
|
||||
pddl_entities_list = tool_non_actions + pddl_actions
|
||||
print('все сущности')
|
||||
print(pddl_entities_list)
|
||||
pddl_entities_list = pddl_non_actions + pddl_actions
|
||||
|
||||
print(export_to_file(tool, pddl_entities_list))
|
||||
# print(export_to_file(pddl_entities_list))
|
||||
domain_export(tool, pddl_entities_list)
|
||||
|
||||
def problem_export(partlist):
|
||||
pass
|
||||
|
||||
|
||||
def predicate_generator():
|
||||
#как определять операции? по тегам, означающим действие и/или подготовку
|
||||
#нужно выделить порядок
|
||||
#как выделить порядок операций для детали?
|
||||
#операции импортируются по порядку сверху вниз.
|
||||
#можно создавать переходы по следующим признакам:
|
||||
#операция создает условие "operation_name_done", следующая операция требует условия "operation_name_n-1_done"
|
||||
#операция при начале делает условие "not operation_name_done"
|
||||
#если операция требует изменения инструмента, то должна выполняться операция по замене инструмента
|
||||
#
|
||||
for n in range(pddl_actions):
|
||||
if pddl_actions[n+1]['Tool'] == pddl_actions[n]['Tool']:
|
||||
#замена инструмента не требуется
|
||||
pddl_actions[n+1]['Conditions'].append(pddl_actions[n]["Label"] + '_done')
|
||||
|
||||
else:
|
||||
#включается операция по замене инструмента
|
||||
pddl_actions[n+1]['Conditions'].append( pddl_actions[n]["Label"] + '_done')
|
||||
pddl_actions[n+1]['Conditions'].append('change_' + pddl_actions[n]['Tool'] + 'to' + pddl_actions[n+1]['Tool'] + '_done' ) #сюда нужно воткнуть операцию по замене
|
||||
#нужно создать операцию, которая произведет эту замену.
|
||||
|
||||
aux_pddl_actions = []
|
||||
|
||||
def auxActionsGenerator(pddl_action_1, pddl_action_2):
|
||||
aux_pddl_actions.append({{'Label': 'change_tool' + pddl_action_1['Tool'] + 'to' + pddl_action_2['Tool'],
|
||||
'Partname': part_operation['Part_label'],
|
||||
'Conditions': tool_operation['Conditions'],
|
||||
'Duration': part_operation['Duration'],
|
||||
'Effects': tool_operation['Effects'],
|
||||
'Parameters': tool_operation['Parameters'],
|
||||
'Type': tool_operation['Type'],
|
||||
'Tool': tool_operation['Label']
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
#генерируется pddl-домен относительно нормально
|
||||
#нужно увязать последовательность операций с пред и пост условиями, создавая предикаты автоматически
|
||||
#problem можно создавать на основе операции сборки. Генератор последовательности сборки выдает основную информацию
|
||||
#для сборки нужно, чтобы все операции подготовки детали были выполнены
|
||||
|
||||
|
||||
|
||||
# какие могут быть ситуации?
|
||||
|
||||
# ряд последовательных операций
|
||||
|
||||
# если станок один:
|
||||
# если операции на одном виде инструментов:
|
||||
# то операция1 имеет пред "операция0 готова"
|
||||
# создает пред "операция1 готова"
|
||||
# операция2 имеет пред "операция1 готова"
|
||||
# создает пред "операция2 готова"
|
||||
# если операция на разных видах инструментов:
|
||||
# то операция1 имеет пред "операция0 готова"
|
||||
# создает пред "операция1 готова"
|
||||
# создает пред "смена инструмента не готова"
|
||||
# операция смены имеет пред "операция1 готова"
|
||||
# имеет пред "смена инструмента не готова"
|
||||
# создает пред "смена инструмента готова"
|
||||
# операция2 имеет пред "операция1 готова"
|
||||
# имеет пред "смена инструмента готова"
|
||||
|
||||
# остальное аналогично
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue