Python pulp.LpStatus() Examples

The following are 7 code examples of pulp.LpStatus(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pulp , or try the search function .
Example #1
Source File: solution.py    From pyDEA with MIT License 6 votes vote down vote up
def _print_for_one_dmu(self, dmu_code):
        ''' Prints on screen all information available for a given DMU.

            Args:
               dmu_code (str): DMU code.
        '''
        print('DMU: {dmu}'.format(
            dmu=self._input_data.get_dmu_user_name(dmu_code)))
        print('code: ', dmu_code)
        if self.lp_status.get(dmu_code):
            print('LP status: {status}'.format(
                status=LpStatus[self.lp_status.get(dmu_code)]))
            if self.lp_status.get(dmu_code) == LpStatusOptimal:
                print('Efficiency score: {score}'.format(
                    score=self.efficiency_scores.get(dmu_code)))
                print('Lambda variables: {vars}'.format(
                    vars=self.get_lambda_variables(dmu_code)))
                print('Input duals: {duals}'.format(
                    duals=self.input_duals.get(dmu_code)))
                print('Output duals: {duals}'.format(
                    duals=self.output_duals.get(dmu_code))) 
Example #2
Source File: lp.py    From scikit-criteria with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def solve(self):
        super(_LP, self).solve()
        objective = pulp.value(self.objective)
        variables, values = [], []
        for v in self.variables():
            variables.append(v.name)
            values.append(v.varValue)
        status = pulp.LpStatus[self.status]
        self.assignVarsVals(dict.fromkeys(variables, None))
        return Result(status_code=self.status,
                      status=status,
                      objective=objective,
                      variables=variables,
                      values=values)


# =============================================================================
# CONCRETE CLASS
# ============================================================================= 
Example #3
Source File: label_prop_v2.py    From transferlearning with MIT License 5 votes vote down vote up
def label_prop(C, nt, Dct, lp="linear"):
    
#Inputs:
#  C      :    Number of share classes between src and tar
#  nt     :    Number of target domain samples
#  Dct    :    All d_ct in matrix form, nt * C
#  lp     :    Type of linear programming: linear (default) | binary
#Outputs:
#  Mcj    :    all M_ct in matrix form, m * C
    
    Dct = abs(Dct)
    model = pulp.LpProblem("Cost minimising problem", pulp.LpMinimize)
    Mcj = pulp.LpVariable.dicts("Probability",
                                ((i, j) for i in range(C) for j in range(nt)),
                                lowBound=0,
                                upBound=1,
                                cat='Continuous')
    
    # Objective Function
    model += (
    pulp.lpSum([Dct[j, i]*Mcj[(i, j)] for i in range(C) for j in range(nt)])
    )
    
    # Constraints
    for j in range(nt):
        model += pulp.lpSum([Mcj[(i, j)] for i in range(C)]) == 1
    for i in range(C):
        model += pulp.lpSum([Mcj[(i, j)] for j in range(nt)]) >= 1
    
    # Solve our problem
    model.solve()
    pulp.LpStatus[model.status]
    Output = [[Mcj[i, j].varValue for i in range(C)] for j in range(nt)]
    
    return np.array(Output) 
Example #4
Source File: solution.py    From pyDEA with MIT License 5 votes vote down vote up
def add_lp_status(self, dmu_code, lp_status):
        ''' Adds LP status corresponding to a given DMU to internal
            data structure.

            Args:
                dmu_code (str): DMU code.
                lp_status (pulp.LpStatus): LP status.
        '''
        self._check_if_dmu_code_exists(dmu_code)
        self.lp_status[dmu_code] = lp_status 
Example #5
Source File: write_data_to_xls.py    From pyDEA with MIT License 4 votes vote down vote up
def create_sheet_onion_rank(self, work_sheet, solution, start_row_index,
                                params_str):
        ''' Writes information about peel the onion solution to a given output.

            Args:
                work_sheet: object that has name attribute and implements
                    write method, it actually writes data to some output
                    (like file, screen, etc.).
                solution (Solution): solution.
                start_row_index (int): initial row index (usually used to append
                    data to existing output).
                params_str (str): string that is usually written in the first
                    row.

            Returns:
                int: index of the last row where data were written plus 1.
        '''
        work_sheet.name = 'OnionRank'
        # in case of max_slacks and peel-the-onion we should not
        # write ranks twice
        if self.count < len(self.ranks):

            work_sheet.write(start_row_index, 0, params_str)
            work_sheet.write(
                start_row_index + 1, 0,
                'Tier / Rank is the run in which DMU became efficient')
            work_sheet.write(start_row_index + 2, 0, 'DMU')
            work_sheet.write(start_row_index + 2, 1, 'Efficiency')
            work_sheet.write(start_row_index + 2, 2, 'Tier / Rank')
            ordered_dmu_codes = solution._input_data.DMU_codes_in_added_order
            row_index = start_row_index + 3
            for dmu_code in ordered_dmu_codes:
                work_sheet.write(
                    row_index, 0,
                    solution._input_data.get_dmu_user_name(dmu_code))
                if solution.lp_status[dmu_code] == pulp.LpStatusOptimal:
                    work_sheet.write(row_index, 1,
                                     solution.get_efficiency_score(dmu_code))
                    work_sheet.write(row_index, 2,
                                     self.ranks[self.count][dmu_code])
                else:
                    work_sheet.write(
                        row_index, 1,
                        pulp.LpStatus[solution.lp_status[dmu_code]])
                row_index += 1
            self.count += 1
            return row_index
        return -1 
Example #6
Source File: write_data_to_xls.py    From pyDEA with MIT License 4 votes vote down vote up
def create_sheet_efficiency_scores(self, work_sheet, solution,
                                       start_row_index, params_str):
        ''' Writes efficiency scores to a given output.

            Args:
                work_sheet: object that has name attribute and implements
                    write method, it actually writes data to some output
                    (like file, screen, etc.).
                solution (Solution): solution.
                start_row_index (int): initial row index (usually used to append
                    data to existing output).
                params_str (str): string that is usually written in the first
                    row.

            Returns:
                int: index of the last row where data were written plus 1.
        '''
        work_sheet.name = 'EfficiencyScores'

        work_sheet.write(start_row_index, 0, params_str)
        work_sheet.write(start_row_index + 1, 0, 'DMU')
        work_sheet.write(start_row_index + 1, 1, 'Efficiency')
        if self.categorical is not None:
            work_sheet.write(start_row_index + 1, 2,
                             'Categorical: {0}'.format(self.categorical))

        ordered_dmu_codes = solution._input_data.DMU_codes_in_added_order
        row_index = 0
        for count, dmu_code in enumerate(ordered_dmu_codes):
            row_index = start_row_index + count + 2
            work_sheet.write(
                row_index, 0, solution._input_data.get_dmu_user_name(dmu_code))
            if solution.lp_status[dmu_code] == pulp.LpStatusOptimal:
                work_sheet.write(
                    row_index, 1, solution.get_efficiency_score(dmu_code))
            else:
                work_sheet.write(
                    row_index, 1, pulp.LpStatus[solution.lp_status[dmu_code]])
            if self.categorical is not None:
                work_sheet.write(
                    row_index, 2,
                    int(solution._input_data.coefficients[
                        dmu_code, self.categorical]))
        return row_index 
Example #7
Source File: write_data_to_xls.py    From pyDEA with MIT License 4 votes vote down vote up
def create_sheet_peers(work_sheet, solution, start_row_index, params_str):
    ''' Writes peers to a given output.

        Args:
            work_sheet: object that has name attribute and implements
                write method, it actually writes data to some output
                (like file, screen, etc.).
            solution (Solution): solution.
            start_row_index (int): initial row index (usually used to append
                data to existing output).
            params_str (str): string that is usually written in the first
                row.

        Returns:
            int: index of the last row where data were written plus 1.
    '''
    work_sheet.name = 'Peers'

    work_sheet.write(start_row_index, 0, params_str)
    work_sheet.write(start_row_index + 1, 0, 'DMU')
    work_sheet.write(start_row_index + 1, 2, 'Peer')
    work_sheet.write(start_row_index + 1, 3, 'Lambda')
    write_classification = False
    if bool(solution.return_to_scale):
        work_sheet.write(start_row_index + 1, 4, 'Classification')
        write_classification = True
        
    ordered_dmu_codes = solution._input_data.DMU_codes_in_added_order
    row_index = start_row_index + 2
    for dmu_code in ordered_dmu_codes:
        work_sheet.write(row_index, 0, solution._input_data.get_dmu_user_name(
            dmu_code))
        if solution.lp_status[dmu_code] == pulp.LpStatusOptimal:
            lambda_vars = solution.get_lambda_variables(dmu_code)
#            sum_of_lambda_values = 0
            once = True
#            for dmu, lambda_value in lambda_vars.items():
#                if lambda_value:
#                    sum_of_lambda_values += lambda_value
            
            for dmu, lambda_value in lambda_vars.items():
                if lambda_value:
                    dmu_name = solution._input_data.get_dmu_user_name(dmu)
                    work_sheet.write(row_index, 2, dmu_name)
                    work_sheet.write(row_index, 3, lambda_value)
                    if write_classification and once:
                        work_sheet.write(
                            row_index, 4, solution.return_to_scale[dmu_code]
                            #_calculate_frontier_classification(sum_of_lambda_values)
                                )

                        once = False
                    row_index += 1

        else:
            work_sheet.write(
                row_index, 2, pulp.LpStatus[solution.lp_status[dmu_code]])
        row_index += 1
    return row_index