コード例 #1
0
ファイル: generate.py プロジェクト: PierreRust/pyDcop
def generate_ising(args):
    domain_size = args.range
    size = args.size
    d = VariableDomain('d', 'dummy', range(domain_size))
    variables = {}
    constraints = {}
    for i in range(size):
        for j in range(size):
            v = Variable('v{}_{}'.format(i, j), d,
                         floor(domain_size * random.random()))
            variables[(i, j)] = v

    for i, j in variables:
        c = _create_ising_constraint(i, j, i, (j + 1) % size, domain_size,
                                     variables)
        constraints[(i, j, i, (j + 1) % size)] = c

        c = _create_ising_constraint(i, j, (i + 1) % size, j, domain_size,
                                     variables)
        constraints[(i, j, (i + 1) % size), j] = c

    dcop = DCOP('radom ising', 'min')
    #dcop.domains = {'d': d}
    #dcop.variables = variables
    dcop._agents_def = {}
    for c in constraints.values():
        dcop.add_constraint(c)

    if args.output:
        outputfile = args.output[0]
        write_in_file(outputfile, dcop_yaml(dcop))
    else:
        print(dcop_yaml(dcop))
コード例 #2
0
ファイル: ising.py プロジェクト: sankarshandamle/pyDcop
def generate(args):

    # Some extra checks on cli parameters!
    if args.row_count <= 2:
        raise ValueError("--row_count: The size must be > 2")
    if args.col_count:
        if args.col_count <= 2:
            raise ValueError("--col_count: The size must be > 2")
        col_count = args.col_count
    else:
        col_count = args.row_count

    dcop, var_mapping, fg_mapping = generate_ising(
        args.row_count,
        col_count,
        args.bin_range,
        args.un_range,
        not args.intentional,
        no_agents=args.no_agents,
        fg_dist=args.fg_dist,
        var_dist=args.var_dist,
    )

    graph = "factor_graph" if args.fg_dist else "constraints_graph"
    output_file = args.output if args.output else "NA"
    dist_result = {
        "inputs": {
            "dist_algo": "NA",
            "dcop": output_file,
            "graph": graph,
            "algo": "NA",
        },
        "cost": None,
    }

    # TODO: generate and output distribution
    if args.output:
        with open(output_file, encoding="utf-8", mode="w") as fo:
            fo.write(dcop_yaml(dcop))
        path, ext = splitext(output_file)
        if args.fg_dist:
            dist_result["distribution"] = fg_mapping
            dist_output_file = f"{path}_fgdist{ext}"
            with open(dist_output_file, encoding="utf-8", mode="w") as fo:
                fo.write(yaml.dump(dist_result))
        if args.var_dist:
            dist_result["distribution"] = var_mapping
            dist_output_file = f"{path}_vardist{ext}"
            with open(dist_output_file, encoding="utf-8", mode="w") as fo:
                fo.write(yaml.dump(dist_result))

    else:
        print(dcop_yaml(dcop))
        if args.fg_dist:
            dist_result["distribution"] = fg_mapping
            print(yaml.dump(dist_result))
        if args.var_dist:
            dist_result["distribution"] = fg_mapping
            print(yaml.dump(dist_result))
コード例 #3
0
ファイル: secp.py プロジェクト: sankarshandamle/pyDcop
def generate_secp(args):
    logger.info("Generate SECP %s", args)
    light_count = args.lights
    model_count = args.models
    rule_count = args.rules
    capacity = args.capacity
    max_model_size = args.max_model_size
    max_rule_size = args.max_rule_size

    light_domain = Domain("light", "light", range(0, 5))

    lights_var, lights_cost = build_lights(light_count, light_domain)

    models_var, models_constraints = build_models(
        light_domain, lights_var, max_model_size, model_count
    )

    rules_constraints = build_rules(rule_count, lights_var, models_var, max_rule_size)

    # Agents : one for each light
    agents = build_agents(lights_var, lights_cost, capacity)

    # Force
    # * each light variable to be hosted on the corresponding agent
    # * model constraint and var are preferred on the same agent

    variables = lights_var.copy()
    variables.update(models_var)

    constraints = models_constraints.copy()
    constraints.update(lights_cost)
    constraints.update(rules_constraints)

    dcop = DCOP(
        "graph coloring",
        "min",
        domains={"light_domain": light_domain},
        variables=variables,
        agents=agents,
        constraints=constraints,
    )

    if args.output:
        outputfile = args.output
        write_in_file(outputfile, dcop_yaml(dcop))
    else:
        print(dcop_yaml(dcop))
コード例 #4
0
ファイル: generate.py プロジェクト: PierreRust/pyDcop
def generate_mixed_problem(args):
    logger.debug('generate_mixed_problem %s ', args)
    variable_count = args.variable_count
    constraint_count = args.constraint_count
    density = args.density
    real_density = density
    domain_range = args.range
    arity = args.arity
    auto_agents = args.agents is None
    capacity = args.capacity
    agents_count = variable_count if auto_agents else args.agents
    nb_max_edges = constraint_count * min(arity, variable_count)
    edges_count = int(nb_max_edges * density)
    hard_count = int(args.hard_constraint * edges_count)
    logger.info(
        'Generating random DCOP graph with %s variables, whose domain '
        'are [0;%s], %s edges, %s agents, %s hard '
        'constraints and %s soft constraints', variable_count,
        domain_range - 1, edges_count, agents_count, hard_count,
        constraint_count - hard_count)

    if arity > variable_count:
        raise ValueError(
            "The arity of a constraint must be at most the "
            "number of variable. Arity: {}, Nb variables: {}".format(
                arity, variable_count))

    if hard_count < 0:
        raise ValueError(
            "The argument '-h' (or '--hard_count') must be "
            "between 0 and 1. Currently set to: {}".format(hard_count))
    # Create sets for the bipartite graph
    if constraint_count <= 0:
        raise ValueError(
            "The argument '-c' (or '--constraint_count') must be "
            "strictly positive. Currently set to: {}".format(constraint_count))
    if variable_count < 0:
        raise ValueError(
            "The argument '-v' (or '--variable_count') must be "
            "at least 1. Currently set to: {}".format(variable_count))
    if arity <= 0:
        raise ValueError("The argument '-a' (or '--arity') must be "
                         "at least 1. Currently set to: {}".format(arity))

    d = VariableDomain('levels', 'level', range(domain_range))
    variables = {}
    agents = {}
    constraints = {}

    if arity == 1:
        if constraint_count != variable_count:
            raise ValueError("For max arity 1 you need the same number of "
                             "variables, constraints and edges. You asked "
                             "for {} variables and {} constraints.".format(
                                 variable_count, constraint_count))
        nodes = [i + 1 for i in range(variable_count)]
        constraints_list = [("c{}".format(i + 1),
                             'hard') if i < hard_count else
                            ("c{}".format(i + 1), 'soft')
                            for i in range(constraint_count)]
        variables = {}
        constraints = {}
        while len(nodes) != 0:
            n = nodes.pop()
            c = constraints_list.pop(
                random.randint(0,
                               len(constraints_list) - 1))
            w = choose_weight()
            hard = c[1] == 'hard'
            objective = find_objective([w], domain_range - 1, hard)
            if hard:
                expression = "float('inf') if " + str(w) + "*v" + str(n) +\
                             " != " + str(objective) + " else 0"
            else:
                expression = str(w) + "*v" + str(n) + " - " + str(objective)

            v = Variable("v" + str(n), d)
            variables["v" + str(n)] = v
            constraints[c[0]] = relation_from_str(c[0], expression, [v])

            if auto_agents:
                a_name = 'a' + str(n)
                agents[a_name] = AgentDef(a_name, capacity)

        if not auto_agents:
            for i in range(agents_count):
                a_name = 'a' + str(i)
                agents[a_name] = AgentDef(a_name, capacity)

    elif arity == 2:
        edges_count = int(variable_count * (variable_count - 1) * density / 2)
        if constraint_count != edges_count:
            logger.warning("edges count is different of constraint count ({} "
                           "!= {}) but for arity 2, constraints are the deges"
                           "of the graph. We use the density ({}) to determine"
                           " the number of edges".format(
                               edges_count, constraint_count, density))
        is_connected = False
        while not is_connected:
            graph = nx.gnp_random_graph(variable_count, density)
            is_connected = nx.is_connected(graph)

        # Compute nb of hard constraints regarding the true density
        real_density = nx.density(graph)
        hard_count = args.hard_constraint * real_density * args.variable_count\
                     * (args.variable_count + 1) / 2

        for i, node in enumerate(graph.nodes_iter()):
            logger.debug('node %s - %s', node, i)
            name = 'v' + str(i)
            variables[name] = Variable(name, d)
            if auto_agents:
                a_name = 'a' + str(i)
                agents[a_name] = AgentDef(a_name, capacity)

        if not auto_agents:
            for i in range(agents_count):
                a_name = 'a' + str(i)
                agents[a_name] = AgentDef(a_name, capacity)

        constraints = {}
        for i, edge in enumerate(graph.edges_iter()):
            logger.debug('edge %s - %s', edge, i)
            name = 'c' + str(i)
            u, v = edge
            weights = [round(choose_weight(), 2), round(choose_weight(), 2)]

            # Create hard_constraints
            if i < hard_count:
                objective = round(find_objective(weights, domain_range, True),
                                  2)
                expression = "0 if v{} != v{} else float(" \
                             "'inf')".format(u, v)
            else:
                max_val = (weights[0] + weights[1]) * domain_range
                expression = 'abs(v{} + v{} - {})'\
                    .format(u, v, round(random.uniform(0, max_val), 2))

            constraints[name] = relation_from_str(name, expression,
                                                  variables.values())
            logger.debug(repr(constraints[name]))

    else:
        if edges_count < constraint_count and arity != 1:
            raise ValueError(
                "The number of edges must be greater or equal to the "
                "number of constraints. Otherwise you have unused "
                "constraints. Edges: {}, Constraints: {}".format(
                    edges_count, constraint_count))
        nodes = [i for i in list(range(variable_count))]
        constraints = [("c{}".format(i), "hard") if i < hard_count else
                       ("c{}".format(i), "soft")
                       for i in list(range(constraint_count))]
        # Randomly add edges
        edges = defaultdict(lambda: [])  # final set of edges

        # Available edges at a given run
        available_edges = {n: constraints.copy() for n in nodes}
        # First, make sure each variable has one constraint
        for n in nodes:
            if constraints:
                node = n
                c = constraints.pop(random.randint(0, len(constraints) - 1))
            else:
                node, c = choose_in_available_edges(available_edges, n)
            add_edge(node, c, available_edges, edges, arity)
            logger.debug('Add edge (%s, %s)', n, c)
        edges_count -= variable_count

        # Second, make sure each constraint is used
        for c in constraints:
            n = random.choice(nodes)
            add_edge(n, c, available_edges, edges, arity)
            edges_count -= 1
            logger.debug('Add edge (%s, %s)', n, c)

        # Third, randomly add remaining constraints
        while edges_count != 0:
            n, c = choose_in_available_edges(available_edges)
            if (n, c) == (None, None):
                # If more edges than possible are asked, returns just the maximum
                # edges (regarding nodes number and constraints arity)
                logger.warning(
                    '%s edges were not added because you asked for too'
                    ' many edges regarding the number of constraints ('
                    '%s) and their maximum arity (%s)',
                    edges_count - len(edges), constraint_count, args.arity)
                break
            else:
                add_edge(n, c, available_edges, edges, arity)
                edges_count -= 1

        # Now create a DCOP from the graph
        for i in nodes:
            name = 'v' + str(i)
            variables[name] = Variable(name, d)
            if auto_agents:
                a_name = 'a' + str(i)
                agents[a_name] = AgentDef(a_name, capacity)

        if not auto_agents:
            for i in range(agents_count):
                a_name = 'a' + str(i)
                agents[a_name] = AgentDef(a_name, capacity)

        constraints = {}
        for c, neighbors in edges.items():
            logger.debug('Constraint %s, variables: %s', c, neighbors)
            name, is_hard = c[0], c[1] == 'hard'
            c_variables = [variables["v" + str(name)] for name in neighbors]
            addition_string = ""
            first = True
            weights = []
            max_val = 0
            for i in neighbors:
                # Add random weights in constraints
                m = round(choose_weight(), 2)
                weights.append(m)
                max_val += m * (domain_range - 1)
                if not first:
                    addition_string += ' + '
                else:
                    first = False
                if m != 1:
                    addition_string += str(m) + '*'
                addition_string += 'v' + str(i) + ' '

            # To ensure that our hard constraints are achievable, we use
            # the value obtained for a set of random values (in the domain)
            # as the objective.

            objective = round(find_objective(weights, domain_range, is_hard),
                              2)

            if is_hard:
                expression = "0 if " + addition_string + " == " + \
                             str(objective) + " else float('inf')"
            else:
                const_function = "abs(" + addition_string
                if objective:
                    expression = const_function + " - " + str(objective) + ")"
                else:
                    expression = addition_string

            constraints[name] = relation_from_str(name, expression,
                                                  c_variables)
            logger.debug(repr(constraints[name]))

    dcop = DCOP('mixed constraints problem',
                'min',
                domains={'levels': d},
                variables=variables,
                constraints=constraints,
                agents=agents)

    if args.output is not None:
        outputfile = args.output[0]
        if args.correct_density:
            outputfile = correct_density(outputfile, real_density)
        write_in_file(outputfile, dcop_yaml(dcop))
    else:
        print(dcop_yaml(dcop))
コード例 #5
0
ファイル: generate.py プロジェクト: PierreRust/pyDcop
def generate_graph_coloring(args):
    logger.debug('generate_graph_coloring %s ', args)
    node_count = args.node_count
    density = args.density
    color_count = args.color_count
    auto_agents = args.agents is None
    agents_count = node_count if auto_agents else args.agents
    capacity = args.capacity
    logger.info(
        'Generating random graph coloring with %s variables, '
        '%s colors, target density %s and %s agents', node_count, color_count,
        args.density, agents_count)

    # First a random graph
    is_connected = False
    if not args.allow_subgraph:
        while not is_connected:
            graph = nx.gnp_random_graph(args.node_count, density)
            is_connected = nx.is_connected(graph)
    else:
        graph = nx.gnp_random_graph(args.node_count, density)
        is_connected = nx.is_connected(graph)

    real_density = nx.density(graph)
    logger.info(nx.info(graph))
    logger.info('Connected : %s', nx.is_connected(graph))
    logger.info('Density %s', nx.density(graph))

    # Now create a DCOP from the graph
    d = VariableDomain('colors', 'color', range(color_count))
    variables = {}
    agents = {}
    for i, node in enumerate(graph.nodes_iter()):
        logger.debug('node %s - %s', node, i)
        name = 'v' + str(i)
        variables[name] = Variable(name, d)
        if auto_agents:
            a_name = 'a' + str(i)
            agents[a_name] = AgentDef(a_name, capacity)

    if not auto_agents:
        for i in range(agents_count):
            a_name = 'a' + str(i)
            agents[a_name] = AgentDef(a_name, capacity)

    constraints = {}
    for i, edge in enumerate(graph.edges_iter()):
        logger.debug('edge %s - %s', edge, i)
        name = 'c' + str(i)
        u, v = edge
        expression = '1000 if v{} == v{} else 0'.format(u, v)
        constraints[name] = relation_from_str(name, expression,
                                              variables.values())
        logger.debug(repr(constraints[name]))

    dcop = DCOP('graph coloring',
                'min',
                domains={'colors': d},
                variables=variables,
                agents=agents,
                constraints=constraints)

    if args.output:
        outputfile = args.output[0]
        if args.correct_density:
            outputfile = correct_density(outputfile, real_density)
        write_in_file(outputfile, dcop_yaml(dcop))
    else:
        print(dcop_yaml(dcop))
コード例 #6
0
ファイル: iot.py プロジェクト: sankarshandamle/pyDcop
def generate_iot(args):
    print("generate iot ", args.output)

    # Constraints and variables with a power-law constraint graph:
    variables, constraints, domain = generate_powerlaw_var_constraints(
        args.num, args.domain, args.range
    )

    # Build a dcop and computation graph with no agents, just to be able to
    # compute the footprint of computations:
    dcop = DCOP(
        "graph coloring",
        "min",
        domains={"d": domain},
        variables=variables,
        agents={},
        constraints=constraints,
    )
    graph_module = import_module("pydcop.computations_graph.factor_graph")
    cg = graph_module.build_computation_graph(dcop)
    algo_module = load_algorithm_module("maxsum")

    footprints = {c.name: algo_module.computation_memory(c) for c in cg.nodes}

    # Generate an agent for each variable computation and assign the
    # computation to that agent.
    agents = {}  # type: Dict[str, AgentDef]
    mapping = defaultdict(lambda: [])  # type: Dict[str, List[str]]
    for comp in cg.nodes:
        if isinstance(comp, VariableComputationNode):
            a_name = agt_name(comp.name)
            agt = AgentDef(
                a_name,
                capacity=footprints[comp.name] * 100,
                default_hosting_cost=10,
                hosting_costs=agt_hosting_costs(comp, cg),
                default_route=1,
                routes=agt_route_costs(comp, cg),
            )
            logger.debug(
                "Create agent %s for computation %s with capacity %s",
                agt.name,
                comp.name,
                agt.capacity,
            )
            agents[agt.name] = agt
            mapping[agt.name].append(comp.name)

    # Now, we have created all the agents and distributed all the variables
    # let's distribute the factor computations.
    msg_load = msg_load_func(cg, algo_module.communication_load)
    factor_mapping = distribute_factors(agents, cg, footprints, mapping, msg_load)
    for a in mapping:
        mapping[a].extend(factor_mapping[a])

    dcop = DCOP(
        "graph coloring",
        "min",
        domains={"d": domain},
        variables=variables,
        agents=agents,
        constraints=constraints,
    )

    distribution = Distribution(mapping)

    if args.output:
        outputfile = args.output
        write_in_file(outputfile, dcop_yaml(dcop))

        dist = distribution.mapping()
        cost = ilp_compref.distribution_cost(
            distribution,
            cg,
            dcop.agents.values(),
            computation_memory=algo_module.computation_memory,
            communication_load=algo_module.communication_load,
        )

        result = {
            "inputs": {
                "dist_algo": "io_problem",
                "dcop": args.output,
                "graph": "factor_graph",
                "algo": "maxsum",
            },
            "distribution": dist,
            "cost": cost,
        }
        outputfile = "dist_" + args.output
        write_in_file(outputfile, yaml.dump(result))
    else:
        print(dcop_yaml(dcop))
コード例 #7
0
def generate(args):
    slots, events, resources = generate_problem_definition(
        args.slots_count,
        args.resources_count,
        args.max_resource_value,
        args.events_count,
        args.max_length_event,
        args.max_resources_event,
    )

    penalty = args.max_resource_value * args.slots_count * args.resources_count
    variables, constraints, agents = peav_model(slots, events, resources,
                                                penalty)

    domains = {
        variable.domain.name: variable.domain
        for variable in variables.values()
    }
    variables = {variable.name: variable for variable in variables.values()}
    # agents_defs = {agent.name: agent for agent, _ in agents.values()}
    # Generate agents hosting and route costs
    agents_defs = {}
    if not args.no_agents:
        for agent, agt_variables in agents.items():
            kw = {}
            kw["hosting_costs"] = {v.name: 0 for v in agt_variables}
            if args.hosting_default:
                kw["default_hosting_cost"] = args.hosting_default
            if args.capacity:
                kw["capacity"] = args.capacity
            if args.routes_default:
                kw["default_route"] = args.routes_default
            agents_defs[agent] = AgentDef(agent, **kw)

    dcop = DCOP(
        "MeetingSceduling",
        objective="max",
        domains=domains,
        variables=variables,
        constraints=constraints,
        agents=agents_defs,
    )

    if not args.no_agents:
        distribution = Distribution({
            agent.name: [v.name for v in agents[agent.name]]
            for agent in agents_defs.values()
        })

    if args.output:
        output_file = args.output
        with open(output_file, encoding="utf-8", mode="w") as fo:
            fo.write(dcop_yaml(dcop))

        if not args.no_agents:
            dist_result = {
                "inputs": {
                    "dist_algo": "peav",
                    "dcop": output_file,
                    "graph": "constraints_graph",
                    "algo": "NA",
                },
                "distribution": distribution.mapping(),
                "cost": None,
            }
            path, ext = splitext(output_file)
            dist_output_file = f"{path}_dist{ext}"
            with open(dist_output_file, encoding="utf-8", mode="w") as fo:
                fo.write(yaml.dump(dist_result))

    else:
        print(dcop_yaml(dcop))

        if not args.no_agents:
            dist_result = {
                "inputs": {
                    "dist_algo": "peav",
                    "dcop": "NA",
                    "graph": "constraints_graph",
                    "algo": "NA",
                },
                "distribution": distribution.mapping(),
                "cost": None,
            }
            # FIXME proper serialization of the distribution:
            print(yaml.dump(dist_result))
コード例 #8
0
ファイル: smallworld.py プロジェクト: sankarshandamle/pyDcop
def generate_small_world(args):
    logger.debug("generate small world problem %s ", args)

    # Erdős-Rényi graph aka binomial graph.
    graph = nx.barabasi_albert_graph(args.num, 2)

    # import matplotlib.pyplot as plt
    # plt.subplot(121)
    # nx.draw(graph)  # default spring_layout
    # plt.show()

    domain = Domain("d", "d", range(args.domain))
    variables = {}
    agents = {}
    for n in graph.nodes:
        v = Variable(var_name(n), domain)
        variables[v.name] = v
        logger.debug("Create var for node %s : %s", n, v)

    constraints = {}
    for i, (n1, n2) in enumerate(graph.edges):
        v1 = variables[var_name(n1)]
        v2 = variables[var_name(n2)]
        values = random_assignment_matrix([v1, v2], range(args.range))
        c = NAryMatrixRelation([v1, v2], values, name=c_name(n1, n2))
        logger.debug("Create constraints for edge (%s, %s) : %s", v1, v2, c)
        constraints[c.name] = c

    dcop = DCOP(
        "graph coloring",
        "min",
        domains={"d": domain},
        variables=variables,
        agents={},
        constraints=constraints,
    )
    graph_module = import_module("pydcop.computations_graph.factor_graph")
    cg = graph_module.build_computation_graph(dcop)
    algo_module = load_algorithm_module("maxsum")

    footprints = {n.name: algo_module.computation_memory(n) for n in cg.nodes}
    f_vals = footprints.values()
    logger.info(
        "%s computations, footprint: \n  sum: %s, avg: %s max: %s, "
        "min: %s",
        len(footprints),
        sum(f_vals),
        sum(f_vals) / len(footprints),
        max(f_vals),
        min(f_vals),
    )

    default_hosting_cost = 2000
    small_agents = [agt_name(i) for i in range(75)]
    small_capa, avg_capa, big_capa = 40, 200, 1000
    avg_agents = [agt_name(i) for i in range(75, 95)]
    big_agents = [agt_name(i) for i in range(95, 100)]
    hosting_factor = 10

    for a in small_agents:
        # communication costs with all other agents
        comm_costs = {other: 6 for other in small_agents if other != a}
        comm_costs.update({other: 8 for other in avg_agents})
        comm_costs.update({other: 10 for other in big_agents})
        # hosting cost for all computations
        hosting_costs = {}
        for n in cg.nodes:
            # hosting_costs[n.name] = hosting_factor * \
            #                         abs(small_capa -footprints[n.name])
            hosting_costs[n.name] = footprints[n.name] / small_capa

        agt = AgentDef(
            a,
            default_hosting_cost=default_hosting_cost,
            hosting_costs=hosting_costs,
            default_route=10,
            routes=comm_costs,
            capacity=small_capa,
        )
        agents[agt.name] = agt
        logger.debug("Create small agt : %s", agt)

    for a in avg_agents:
        # communication costs with all other agents
        comm_costs = {other: 8 for other in small_agents}
        comm_costs.update({other: 2 for other in avg_agents if other != a})
        comm_costs.update({other: 4 for other in big_agents})
        # hosting cost for all computations
        hosting_costs = {}
        for n in cg.nodes:
            # hosting_costs[n.name] = hosting_factor * \
            #                         abs(avg_capa - footprints[n.name])
            hosting_costs[n.name] = footprints[n.name] / avg_capa

        agt = AgentDef(
            a,
            default_hosting_cost=default_hosting_cost,
            hosting_costs=hosting_costs,
            default_route=10,
            routes=comm_costs,
            capacity=avg_capa,
        )
        agents[agt.name] = agt
        logger.debug("Create avg agt : %s", agt)

    for a in big_agents:
        # communication costs with all other agents
        comm_costs = {other: 10 for other in small_agents}
        comm_costs.update({other: 4 for other in avg_agents})
        comm_costs.update({other: 1 for other in big_agents if other != a})
        # hosting cost for all computations
        hosting_costs = {}
        for n in cg.nodes:
            hosting_costs[n.name] = footprints[n.name] / big_capa

        agt = AgentDef(
            a,
            default_hosting_cost=default_hosting_cost,
            hosting_costs=hosting_costs,
            default_route=10,
            routes=comm_costs,
            capacity=big_capa,
        )
        agents[agt.name] = agt
        logger.debug("Create big agt : %s", agt)

    dcop = DCOP(
        "graph coloring",
        "min",
        domains={"d": domain},
        variables=variables,
        agents=agents,
        constraints=constraints,
    )

    if args.output:
        outputfile = args.output[0]
        write_in_file(outputfile, dcop_yaml(dcop))
    else:
        print(dcop_yaml(dcop))