def _update_input_problem(self): problem_name = self.get_section_property(InputParser.PROBLEM, InputParser.NAME) if problem_name is None: problem_name = self.get_property_default_value( InputParser.PROBLEM, InputParser.NAME) if problem_name is None: raise AlgorithmError( "No algorithm 'problem' section found on input.") input_name = self.get_section_property(InputParser.INPUT, InputParser.NAME) if input_name is not None and problem_name in InputParser.get_input_problems( input_name): return for input_name in local_inputs(): if problem_name in self.get_input_problems(input_name): # set to the first input to solve the problem self.set_section_property(InputParser.INPUT, InputParser.NAME, input_name) return # no input solve this problem, remove section self.delete_section(InputParser.INPUT)
def get_input_section_names(self): problem_name = None if self._parser is not None: problem_name = self.get_section_property(InputParser.PROBLEM,InputParser.NAME) if problem_name is None: problem_name = self.get_property_default_value(InputParser.PROBLEM,InputParser.NAME) if problem_name is None: return local_inputs() input_names = [] for input_name in local_inputs(): problems = InputParser.get_input_problems(input_name) if problem_name in problems: input_names.append(input_name) return input_names
def __init__(self): """Create Model object.""" self._property_titles = OrderedDict() self._sections = OrderedDict() self._sections[Model._INPUT_NAME] = OrderedDict() self._property_titles[Model._INPUT_NAME] = OrderedDict() for input_name in local_inputs(): config = copy.deepcopy(get_input_configuration(input_name)) self._populate_section(Model._INPUT_NAME, input_name, config) for pluggable_type in local_pluggables_types(): self._sections[pluggable_type] = OrderedDict() self._property_titles[pluggable_type] = OrderedDict() for pluggable_name in local_pluggables(pluggable_type): config = copy.deepcopy( get_pluggable_configuration(pluggable_type, pluggable_name)) self._populate_section(pluggable_type, pluggable_name, config)
def _update_algorithm_input_schema(self): # find alogorithm input default_name = self.get_property_default_value(InputParser.INPUT, InputParser.NAME) input_name = self.get_section_property(InputParser.INPUT, InputParser.NAME, default_name) if input_name is None: # find the first valid input for the problem problem_name = self.get_section_property(InputParser.PROBLEM, InputParser.NAME) if problem_name is None: problem_name = self.get_property_default_value( InputParser.PROBLEM, InputParser.NAME) if problem_name is None: raise AlgorithmError( "No algorithm 'problem' section found on input.") for name in local_inputs(): if problem_name in self.get_input_problems(name): # set to the first input to solve the problem input_name = name break if input_name is None: # just remove fromm schema if none solves the problem if InputParser.INPUT in self._schema['definitions']: del self._schema['definitions'][InputParser.INPUT] if InputParser.INPUT in self._schema['properties']: del self._schema['properties'][InputParser.INPUT] return if default_name is None: default_name = input_name config = {} try: config = get_input_configuration(input_name) except: pass input_schema = config[ 'input_schema'] if 'input_schema' in config else {} properties = input_schema[ 'properties'] if 'properties' in input_schema else {} properties[InputParser.NAME] = {'type': 'string'} required = input_schema[ 'required'] if 'required' in input_schema else [] additionalProperties = input_schema[ 'additionalProperties'] if 'additionalProperties' in input_schema else True if default_name is not None: properties[InputParser.NAME]['default'] = default_name required.append(InputParser.NAME) if InputParser.INPUT not in self._schema['definitions']: self._schema['definitions'][InputParser.INPUT] = {'type': 'object'} if InputParser.INPUT not in self._schema['properties']: self._schema['properties'][InputParser.INPUT] = { '$ref': "#/definitions/{}".format(InputParser.INPUT) } self._schema['definitions'][ InputParser.INPUT]['properties'] = properties self._schema['definitions'][InputParser.INPUT]['required'] = required self._schema['definitions'][ InputParser.INPUT]['additionalProperties'] = additionalProperties