def test_build_single_var(self): v1 = Variable('v1', [1, 2, 3]) dcop = DCOP('test', 'min') dcop.variables = {'v1': v1} cg = build_computation_graph(dcop) self.assertEqual(len(cg.nodes), 1) self.assertEqual(cg.computation('v1').variable, v1) self.assertEqual(len(cg.links), 0)
def load_dcop(dcop_str: str) -> DCOP: loaded = yaml.load(dcop_str) if 'name' not in loaded: raise ValueError('Missing name in dcop string') if 'objective' not in loaded or loaded['objective'] not in ['min', 'max']: raise ValueError('Objective is mandatory and must be min or max') dcop = DCOP(loaded['name'], loaded['objective'], loaded['description'] if 'description' in loaded else '') dcop.domains = _build_domains(loaded) dcop.variables = _build_variables(loaded, dcop) dcop.external_variables = _build_external_variables(loaded, dcop) dcop._constraints = _build_constraints(loaded, dcop) dcop._agents_def = _build_agents(loaded) dcop.dist_hints = _build_dist_hints(loaded, dcop) return dcop
def load_dcop(dcop_str: str) -> DCOP: loaded = yaml.load(dcop_str, Loader=yaml.FullLoader) if "name" not in loaded: raise ValueError("Missing name in dcop string") if "objective" not in loaded or loaded["objective"] not in ["min", "max"]: raise ValueError("Objective is mandatory and must be min or max") dcop = DCOP( loaded["name"], loaded["objective"], loaded["description"] if "description" in loaded else "", ) dcop.domains = _build_domains(loaded) dcop.variables = _build_variables(loaded, dcop) dcop.external_variables = _build_external_variables(loaded, dcop) dcop._constraints = _build_constraints(loaded, dcop) dcop._agents_def = _build_agents(loaded) dcop.dist_hints = _build_dist_hints(loaded, dcop) return dcop