def solve(self, hosts, filter_properties):
        """This method returns a list of tuples - (host, instance_uuid)
        that are returned by the solver. Here the assumption is that
        all instance_uuids have the same requirement as specified in
        filter_properties.
        """
        host_instance_combinations = []

        num_instances = filter_properties['num_instances']
        num_hosts = len(hosts)

        instance_uuids = filter_properties.get('instance_uuids') or [
                '(unknown_uuid)' + str(i) for i in xrange(num_instances)]

        filter_properties.setdefault('solver_cache', {})
        filter_properties['solver_cache'].update(
                {'cost_matrix': [],
                'constraint_matrix': []})

        cost_matrix = self._get_cost_matrix(hosts, filter_properties)
        cost_matrix = self._adjust_cost_matrix(cost_matrix)
        constraint_matrix = self._get_constraint_matrix(hosts,
                                                        filter_properties)

        # Create dictionaries mapping temporary host/instance keys to
        # hosts/instance_uuids. These temorary keys are to be used in the
        # solving process since we need a convention of lp variable names.
        host_keys = ['Host' + str(i) for i in xrange(num_hosts)]
        host_key_map = dict(zip(host_keys, hosts))
        instance_num_keys = ['InstanceNum' + str(i) for
                            i in xrange(num_instances + 1)]
        instance_num_key_map = dict(zip(instance_num_keys,
                                        xrange(num_instances + 1)))

        # create the pulp variables
        variable_matrix = [
                [pulp.LpVariable('HI_' + host_key + '_' + instance_num_key,
                0, 1, constants.LpInteger)
                for instance_num_key in instance_num_keys]
                for host_key in host_keys]

        # create the 'prob' variable to contain the problem data.
        prob = pulp.LpProblem("Host Instance Scheduler Problem",
                                constants.LpMinimize)

        # add cost function to pulp solver
        cost_variables = [variable_matrix[i][j] for i in xrange(num_hosts)
                                        for j in xrange(num_instances + 1)]
        cost_coefficients = [cost_matrix[i][j] for i in xrange(num_hosts)
                                        for j in xrange(num_instances + 1)]
        prob += (pulp.lpSum([cost_coefficients[i] * cost_variables[i]
                for i in xrange(len(cost_variables))]), "Sum_Costs")

        # add constraints to pulp solver
        for i in xrange(num_hosts):
            for j in xrange(num_instances + 1):
                if constraint_matrix[i][j] is False:
                    prob += (variable_matrix[i][j] == 0,
                            "Cons_Host_%s" % i + j % "_NumInst_%s")

        # add additional constraints to ensure the problem is valid
        # (1) non-trivial solution: number of all instances == that requested
        prob += (pulp.lpSum([variable_matrix[i][j] * j for i in
                xrange(num_hosts) for j in xrange(num_instances + 1)]) ==
                num_instances, "NonTrivialCons")
        # (2) valid solution: each host is assigned 1 num-instances value
        for i in xrange(num_hosts):
            prob += (pulp.lpSum([variable_matrix[i][j] for j in
                    xrange(num_instances + 1)]) == 1, "ValidCons_Host_%s" % i)

        # The problem is solved using PULP's choice of Solver.
        prob.solve(pulp_solver_classes.PULP_CBC_CMD(
                maxSeconds=CONF.solver_scheduler.pulp_solver_timeout_seconds))

        # Create host-instance tuples from the solutions.
        if pulp.LpStatus[prob.status] == 'Optimal':
            num_insts_on_host = {}
            for v in prob.variables():
                if v.name.startswith('HI'):
                    (host_key, instance_num_key) = v.name.lstrip('HI').lstrip(
                                                        '_').split('_')
                    if v.varValue == 1:
                        num_insts_on_host[host_key] = (
                                        instance_num_key_map[instance_num_key])
            instances_iter = iter(instance_uuids)
            for host_key in host_keys:
                num_insts_on_this_host = num_insts_on_host.get(host_key, 0)
                for i in xrange(num_insts_on_this_host):
                    host_instance_combinations.append(
                            (host_key_map[host_key], instances_iter.next()))
        else:
            LOG.warn(_LW("Pulp solver didnot find optimal solution! "
                    "reason: %s"), pulp.LpStatus[prob.status])
            host_instance_combinations = []

        return host_instance_combinations
dataset/ETHPy150Open openstack/nova-solver-scheduler/nova_solverscheduler/scheduler/solvers/pulp_solver.py/PulpSolver.solve/swapped operands of `%`