示例#1
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
示例#2
0
文件: yamldcop.py 项目: qslim/pyDcop
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