In [1]:
# import cvxopt
# import cvxopt.glpk
# from cvxopt import matrix, solvers
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import timedelta
import datetime
import seaborn as sns
import itertools
from scipy.linalg import block_diag
import time
import os
import pickle
from scipy.misc import comb
from itertools import combinations
from functools import partial

In [2]:
from __future__ import print_function

import sys

import cplex
from cplex.exceptions import CplexError

In [3]:
profile = np.array([list(np.random.permutation(range(1,11))) for i in range(5)])

In [179]:
stringmatrix = '['
for i in range(profile.shape[0]):
    for j in range(profile.shape[1]):
        if j!=profile.shape[1]-1:
            stringmatrix+=str(profile[i][j])+','
        else:
            stringmatrix+=str(profile[i][j])+';'
stringmatrix=stringmatrix[:-1]
stringmatrix+=']'
print (stringmatrix)


[2,4,3,1,9,7,8,6,5,10;10,4,1,8,5,9,7,2,3,6;2,3,8,10,7,1,4,9,5,6;10,5,4,7,9,2,1,8,6,3;7,1,4,2,9,6,8,10,3,5]

In [5]:
for p in [1,2,3]:
    for typ in ['rate','sort']:
        with open('./q{}_{}_profile.p'.format(p,typ),'rb') as file_:
            profile = pickle.load(file_).astype(np.int64)
            print(profile)
            n,m = len(profile), len(profile[0])
            # print(n, m)

            k=4

            def Ind(m,k,i,r):
                return (i-1)*(m-k+1)+r+m
            IndY = partial(Ind,m,k)
            # IndY(1,1)

            nIneq  = int(n*((m-k+2)*(m-k+3)/2-1)+comb(m,k))
            nEq = 1
            nVar = int(m+n*(m-k+1)+1)
            Aineq = np.zeros((nIneq, nVar))
            bineq = np.zeros((nIneq, 1))
            Aeq = np.zeros((nEq, nVar))
            beq = np.zeros((nEq, 1))
            f = np.zeros((nVar, 1))
            ctype = 'B'*(nVar-1)+'C'
            f[-1] = 1
            Aeq[0][0:m] = 1
            beq = k
            countIneq = 1

            for i in range(1,n+1):
                for r in range(1,m-k+2):
                    for j in range(1,r+1):
                        Aineq[countIneq-1, IndY(i,r)-1] = 1
            #             print(IndY(i,r))
            #             print(Aineq)
                        Aineq[countIneq-1, profile[i-1,j-1]-1] = 1
            #             print (Aineq)
                        bineq[countIneq-1] = 1
                        countIneq = countIneq + 1
                    Aineq[countIneq-1, IndY(i,r)-1] = -1
                    for j in range(1,r+1):
                        Aineq[countIneq-1, profile[i-1,j-1]-1] = -1
                    bineq[countIneq-1] = -1
                    countIneq = countIneq + 1
            list_T = np.array([list(int(y)+1 for y in x) for x in list(combinations(range(m),k))])
            for indT in range(1, list_T.shape[0]+1):
                T = list_T[indT-1]
                first_indices_T = np.array([[i for i,elem in enumerate(x) if x[i] in T][0] + 1 for x in profile])
                Aineq[countIneq-1, nVar-1] = -1
                for i in range(1,n+1):
                    Aineq[countIneq-1,IndY(i,first_indices_T[i-1])-1] = 1./first_indices_T[i-1]
                countIneq = countIneq + 1

            # data common to all populateby functions
            my_obj = list(i[0] for i in f)
            my_ub = [cplex.infinity]*len(f)
            my_lb = [0.0]*len(f)
            my_ctype = ctype
            my_colnames = ['x{}'.format(i) for i in range(len(f))]
            my_rhs = list(i[0] for i in bineq) + [float(beq)]
            my_rownames = ['r{}'.format(i) for i in range(nIneq+nEq)]
            my_sense = 'L'*nIneq+'E'*nEq
        
            def populatebynonzero(prob):
                prob.objective.set_sense(prob.objective.sense.minimize)

                prob.linear_constraints.add(rhs=my_rhs, senses=my_sense,
                                            names=my_rownames)
                prob.variables.add(obj=my_obj, lb=my_lb, ub=my_ub, types=my_ctype,
                                   names=my_colnames)

                rows, cols = np.nonzero(np.concatenate((Aineq,Aeq)))
                rows=list(rows)
                cols=list(cols)
                vals = [np.concatenate((Aineq,Aeq))[rows[i],cols[i]] for i in range(len(rows))]

                prob.linear_constraints.set_coefficients(zip(rows, cols, vals))


            def mipex1(pop_method):

                try:
                    my_prob = cplex.Cplex()

                    handle = populatebynonzero(my_prob)

                    my_prob.solve()
                except CplexError as exc:
                    print(exc)
                    return

                print()
                # solution.get_status() returns an integer code
                print("Solution status = ", my_prob.solution.get_status(), ":", end=' ')
                # the following line prints the corresponding string
                print(my_prob.solution.status[my_prob.solution.get_status()])
                print("Solution value  = ", my_prob.solution.get_objective_value())

                numcols = my_prob.variables.get_num()
                numrows = my_prob.linear_constraints.get_num()

                slack = my_prob.solution.get_linear_slacks()
                x = my_prob.solution.get_values()

            #     for j in range(numrows):
            #         print("Row %d:  Slack = %10f" % (j, slack[j]))
                for j in range(m):
                    print("Column %d:  Value = %10f" % (j, x[j]))
                print ("Column %d:  Value = %10f" % (numcols-1, x[numcols-1]))
                return x[:10]

            choices = mipex1('n')
            print (list((np.array(np.where(np.array(choices)>0.0))+1)[0]))
            selected_points = list((np.array(np.where(np.array(choices)>0.5))+1)[0])
            with open('./q{}_{}_results.p'.format(p,typ),'wb') as file_:
                pickle.dump(selected_points, file_)


[[ 7  4  9  8  3  2  6  1 10  5]
 [ 1  9  3  2  8  7  6 10  4  5]
 [ 1  8  4  5  2 10  7  6  3  9]
 [ 7  2  6  1  9  5  8  3  4 10]
 [ 8  5  1 10  7  2  6  9  4  3]
 [ 2  9  7  3  1 10  6  4  5  8]
 [10  8  5  2  4  3  9  7  1  6]
 [ 4  8  1 10  6  7  9  5  3  2]
 [ 8  9 10  1  5  4  3  2  7  6]
 [ 1 10  7  4  2  3  6  9  5  8]
 [ 2  8  4  7  3  9  5 10  6  1]
 [ 8  9  5  3 10  1  2  7  6  4]
 [ 3  2  9  1  7  4  6 10  8  5]
 [ 3 10  2  6  9  5  7  4  8  1]
 [ 7  5  9  1  8  6 10  2  4  3]
 [ 1  2  9  7  6  8  5  3  4 10]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 19 rows and 0 columns.
Aggregator did 16 substitutions.
Reduced MIP has 736 rows, 107 columns, and 4179 nonzeros.
Reduced MIP has 106 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (5.15 ticks)
Found incumbent of value 4.000000 after 0.02 sec. (5.75 ticks)
Probing fixed 16 vars, tightened 0 bounds.
Probing time = 0.02 sec. (10.26 ticks)
Cover probing fixed 0 vars, tightened 11 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 523 rows and 72 columns.
MIP Presolve modified 277 coefficients.
Reduced MIP has 213 rows, 35 columns, and 1254 nonzeros.
Reduced MIP has 34 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (4.64 ticks)
Probing fixed 30 vars, tightened 1 bounds.
Probing changed sense of 2 constraints.
Probing time = 0.00 sec. (0.32 ticks)
Cover probing fixed 0 vars, tightened 105 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 213 rows and 35 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.12 ticks)

Root node processing (before b&c):
  Real time             =    0.07 sec. (21.77 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.07 sec. (21.77 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  4.0
Column 0:  Value =   1.000000
Column 1:  Value =   1.000000
Column 2:  Value =   0.000000
Column 3:  Value =   0.000000
Column 4:  Value =  -0.000000
Column 5:  Value =  -0.000000
Column 6:  Value =   1.000000
Column 7:  Value =   1.000000
Column 8:  Value =  -0.000000
Column 9:  Value =   0.000000
Column 122:  Value =   4.000000
[1, 2, 7, 8]
[[ 4  6 10  7  9  5  8  3  1  2]
 [ 3  2  1  8  7 10  5  4  9  6]
 [ 6  4  8  7  5  9 10  3  1  2]
 [ 5  7  4  2 10  9  1  8  6  3]
 [ 6  3  9  5  4 10  1  2  8  7]
 [ 6  1  3  7  8  5  4 10  2  9]
 [ 7  4  9  1  3  5  6  8 10  2]
 [ 3  1  2 10  6  5  7  4  8  9]
 [ 1  9  5  8  4  3  6  2  7 10]
 [ 7  3  5  6  8  4  2 10  1  9]
 [ 2  4  5  6  7  8  3  9  1 10]
 [ 2  5  4  7  6  9  3  8  1 10]
 [ 2  4  1  9  8  7  3  6  5 10]
 [ 3  4  5  8  7  2  6 10  1  9]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 25 rows and 0 columns.
Aggregator did 14 substitutions.
Reduced MIP has 662 rows, 95 columns, and 3647 nonzeros.
Reduced MIP has 94 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (4.43 ticks)
Found incumbent of value 6.000000 after 0.02 sec. (4.96 ticks)
Probing fixed 14 vars, tightened 0 bounds.
Probing time = 0.01 sec. (8.47 ticks)
Cover probing fixed 0 vars, tightened 9 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 183 rows and 27 columns.
Reduced MIP has 479 rows, 68 columns, and 3056 nonzeros.
Reduced MIP has 67 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (4.01 ticks)
Probing fixed 28 vars, tightened 0 bounds.
Probing time = 0.01 sec. (4.56 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 185 rows and 30 columns.
MIP Presolve modified 4 coefficients.
Reduced MIP has 294 rows, 38 columns, and 1885 nonzeros.
Reduced MIP has 37 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (2.37 ticks)
Probing time = 0.00 sec. (1.73 ticks)
Tried aggregator 1 time.
Reduced MIP has 294 rows, 38 columns, and 1885 nonzeros.
Reduced MIP has 37 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (1.07 ticks)
Probing time = 0.00 sec. (1.69 ticks)
Clique table members: 378.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.58 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                            6.0000        1.0000            83.33%
      0     0        2.6818    11        6.0000        2.6818       17   55.30%
      0     0        2.9795    10        6.0000      Cuts: 24       28   50.34%
*     0+    0                            3.0000        2.9795             0.68%
      0     0        cutoff              3.0000                     28    0.00%
Elapsed time = 0.15 sec. (38.22 ticks, tree = 0.01 MB, solutions = 2)

Mixed integer rounding cuts applied:  2
Zero-half cuts applied:  4
Gomory fractional cuts applied:  1

Root node processing (before b&c):
  Real time             =    0.16 sec. (38.23 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.16 sec. (38.23 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  3.0
Column 0:  Value =   0.000000
Column 1:  Value =   1.000000
Column 2:  Value =   1.000000
Column 3:  Value =   0.000000
Column 4:  Value =   0.000000
Column 5:  Value =   1.000000
Column 6:  Value =   1.000000
Column 7:  Value =  -0.000000
Column 8:  Value =  -0.000000
Column 9:  Value =  -0.000000
Column 108:  Value =   3.000000
[2, 3, 6, 7]
[[ 4  3  8  1  2 10  9  7  6  5]
 [ 8  6  5  7  1  4  9  3  2 10]
 [ 3  7  6  1  4 10  9  5  8  2]
 [ 2  7  4 10  9  1  5  8  3  6]
 [10  6  1  9  8  2  4  7  5  3]
 [ 1  6  4  2  8  5  7  3 10  9]
 [ 4  2  7  8  5  3  1 10  9  6]
 [ 7  9  6 10  1  3  2  5  4  8]
 [ 9  4  3  8  6  2  7  1  5 10]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 9 rows and 0 columns.
Aggregator did 9 substitutions.
Reduced MIP has 508 rows, 65 columns, and 2809 nonzeros.
Reduced MIP has 64 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (2.81 ticks)
Found incumbent of value 6.833333 after 0.02 sec. (5.18 ticks)
Probing fixed 9 vars, tightened 0 bounds.
Probing time = 0.01 sec. (4.80 ticks)
Cover probing fixed 0 vars, tightened 1 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 76 rows and 10 columns.
Reduced MIP has 432 rows, 55 columns, and 2592 nonzeros.
Reduced MIP has 54 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.14 ticks)
Probing time = 0.00 sec. (2.28 ticks)
Tried aggregator 1 time.
Reduced MIP has 432 rows, 55 columns, and 2592 nonzeros.
Reduced MIP has 54 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (1.66 ticks)
Probing time = 0.00 sec. (2.28 ticks)
Clique table members: 648.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (1.27 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                            6.8333        1.0000            85.37%
      0     0        2.2857    16        6.8333        2.2857       35   66.55%
*     0+    0                            4.0000        2.2857            42.86%
      0     0        2.5006    17        4.0000      Cuts: 11       50   37.48%
      0     0        2.5941    17        4.0000       Cuts: 8       64   35.15%
      0     0        2.6039    18        4.0000      Cuts: 12       73   34.90%
      0     0        2.6094    19        4.0000    MIRcuts: 4       79   34.76%

Repeating presolve.
Tried aggregator 1 time.
MIP Presolve eliminated 134 rows and 18 columns.
Reduced MIP has 298 rows, 37 columns, and 1824 nonzeros.
Reduced MIP has 36 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (1.91 ticks)
Probing fixed 15 vars, tightened 0 bounds.
Probing time = 0.00 sec. (1.06 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 88 rows and 15 columns.
MIP Presolve modified 4 coefficients.
Reduced MIP has 210 rows, 22 columns, and 1218 nonzeros.
Reduced MIP has 21 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (1.18 ticks)
Probing time = 0.00 sec. (0.31 ticks)
Tried aggregator 1 time.
Reduced MIP has 210 rows, 22 columns, and 1218 nonzeros.
Reduced MIP has 21 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (0.65 ticks)
Represolve time = 0.04 sec. (5.97 ticks)
Probing time = 0.00 sec. (0.30 ticks)
Clique table members: 66.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.75 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                            4.0000        2.6094            34.76%
      0     0        2.6119    18        4.0000        2.6119      115   34.70%
      0     0        2.6491    15        4.0000   LiftProj: 6      124   33.77%
      0     0        2.6619    17        4.0000       Cuts: 7      139   33.45%
      0     0        2.6667    18        4.0000       Cuts: 9      145   33.33%
      0     0        2.6753    19        4.0000       Cuts: 3      153   33.12%
      0     0        2.6798    18        4.0000       Cuts: 8      160   33.00%
      0     0        2.6804    19        4.0000       Cuts: 9      164   32.99%
      0     0        2.6817    17        4.0000    MIRcuts: 1      167   32.96%
      0     0        2.6817    18        4.0000    MIRcuts: 1      168   32.96%
      0     0        cutoff              4.0000        4.0000      168    0.00%
Elapsed time = 0.47 sec. (75.18 ticks, tree = 0.01 MB, solutions = 2)

Clique cuts applied:  2
Implied bound cuts applied:  1
Mixed integer rounding cuts applied:  3
Lift and project cuts applied:  6
Gomory fractional cuts applied:  2

Root node processing (before b&c):
  Real time             =    0.48 sec. (75.19 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.48 sec. (75.19 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  4.0
Column 0:  Value =   0.000000
Column 1:  Value =   0.000000
Column 2:  Value =   0.000000
Column 3:  Value =   1.000000
Column 4:  Value =  -0.000000
Column 5:  Value =  -0.000000
Column 6:  Value =   1.000000
Column 7:  Value =   1.000000
Column 8:  Value =   0.000000
Column 9:  Value =   1.000000
Column 73:  Value =   4.000000
[4, 7, 8, 10]
[[ 2  3 10  1  7  9  8  4  5  6]
 [ 2  1  6  5 10  3  9  7  4  8]
 [ 1  7  8 10  9  3  5  4  2  6]
 [ 7  2  6  9  5 10  8  4  1  3]
 [ 3  4  5  2 10  9  6  7  1  8]
 [ 6  5 10  7  8  1  4  3  2  9]
 [10  4  3  2  8  7  1  6  9  5]
 [ 2  1  7 10  9  8  3  4  5  6]
 [ 2  4  1  8 10  7  5  3  9  6]
 [10  5  8  9  4  2  3  6  1  7]
 [ 7  6  5  9  1  3  2  8  4 10]
 [ 4  5  2  1  7  9  6  3 10  8]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 20 rows and 0 columns.
Aggregator did 12 substitutions.
Reduced MIP has 599 rows, 83 columns, and 3279 nonzeros.
Reduced MIP has 82 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.72 ticks)
Found incumbent of value 10.333333 after 0.02 sec. (7.03 ticks)
Probing fixed 12 vars, tightened 0 bounds.
Probing time = 0.01 sec. (6.47 ticks)
Cover probing fixed 0 vars, tightened 2 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 100 rows and 13 columns.
Reduced MIP has 499 rows, 70 columns, and 2931 nonzeros.
Reduced MIP has 69 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.78 ticks)
Probing time = 0.00 sec. (2.74 ticks)
Tried aggregator 1 time.
Reduced MIP has 499 rows, 70 columns, and 2931 nonzeros.
Reduced MIP has 69 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (1.98 ticks)
Probing time = 0.00 sec. (2.73 ticks)
Clique table members: 1061.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (1.08 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                           10.3333        1.0000            90.32%
      0     0        2.3590    14       10.3333        2.3590       26   77.17%
*     0+    0                            3.0000        2.3590            21.37%
      0     0        2.6939    14        3.0000      Cuts: 14       48   10.20%
      0     0        cutoff              3.0000                     55    0.00%
Elapsed time = 0.11 sec. (38.16 ticks, tree = 0.01 MB, solutions = 2)

Mixed integer rounding cuts applied:  5
Lift and project cuts applied:  1
Gomory fractional cuts applied:  1

Root node processing (before b&c):
  Real time             =    0.11 sec. (38.18 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.11 sec. (38.18 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  3.0
Column 0:  Value =   0.000000
Column 1:  Value =   1.000000
Column 2:  Value =   1.000000
Column 3:  Value =   0.000000
Column 4:  Value =  -0.000000
Column 5:  Value =   0.000000
Column 6:  Value =   1.000000
Column 7:  Value =  -0.000000
Column 8:  Value =  -0.000000
Column 9:  Value =   1.000000
Column 94:  Value =   3.000000
[2, 3, 7, 10]
[[ 3  4  6  2 10  5  7  1  8  9]
 [ 3  8  6  4 10  7  5  2  9  1]
 [ 8  6  2  9  1 10  3  7  5  4]
 [ 4  9  6  5  2 10  3  8  7  1]
 [ 6  9  3 10  8  2  4  1  7  5]
 [ 7  1  3  4  6  5  2  9 10  8]
 [ 5  6  4  3  9  7  2 10  1  8]
 [ 6  2  3  5  7 10  4  1  9  8]
 [ 8  5 10  7  2  6  1  3  4  9]
 [ 4  6  2  9 10  5  7  3  1  8]
 [ 9  4  6  7  3  1  2  8 10  5]
 [ 5 10  7  8  1  3  4  6  2  9]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 24 rows and 0 columns.
Aggregator did 12 substitutions.
Reduced MIP has 595 rows, 83 columns, and 3233 nonzeros.
Reduced MIP has 82 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.72 ticks)
Found incumbent of value 4.000000 after 0.01 sec. (4.20 ticks)
Probing fixed 12 vars, tightened 0 bounds.
Probing time = 0.01 sec. (6.61 ticks)
Cover probing fixed 0 vars, tightened 9 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 151 rows and 22 columns.
MIP Presolve modified 3 coefficients.
Reduced MIP has 444 rows, 61 columns, and 2779 nonzeros.
Reduced MIP has 60 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.52 ticks)
Probing fixed 43 vars, tightened 0 bounds.
Probing changed sense of 2 constraints.
Probing time = 0.00 sec. (2.69 ticks)
Cover probing fixed 0 vars, tightened 1 bounds.
Tried aggregator 2 times.
MIP Presolve eliminated 309 rows and 43 columns.
MIP Presolve modified 222 coefficients.
Aggregator did 2 substitutions.
Reduced MIP has 133 rows, 16 columns, and 737 nonzeros.
Reduced MIP has 15 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.63 ticks)
Probing time = 0.00 sec. (0.21 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 9 rows and 0 columns.
Reduced MIP has 124 rows, 16 columns, and 692 nonzeros.
Reduced MIP has 15 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.61 ticks)
Probing time = 0.00 sec. (0.19 ticks)
Clique table members: 62.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.29 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                            4.0000        2.0000            50.00%
      0     0        2.9308    11        4.0000        2.9308       18   26.73%
      0     0        3.1604    11        4.0000      Cuts: 43       28   20.99%
      0     0        3.2957    10        4.0000      Cuts: 21       36   17.61%
      0     0        3.3125    12        4.0000       Cuts: 8       39   17.19%
      0     0        3.3463    12        4.0000       Cuts: 6       43   16.34%
      0     0        cutoff              4.0000        4.0000       43    0.00%
Elapsed time = 0.13 sec. (29.56 ticks, tree = 0.01 MB, solutions = 1)

Implied bound cuts applied:  4
Mixed integer rounding cuts applied:  1
Gomory fractional cuts applied:  2

Root node processing (before b&c):
  Real time             =    0.13 sec. (29.57 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.13 sec. (29.57 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  4.0
Column 0:  Value =   0.000000
Column 1:  Value =   0.000000
Column 2:  Value =   1.000000
Column 3:  Value =   1.000000
Column 4:  Value =   0.000000
Column 5:  Value =   1.000000
Column 6:  Value =   0.000000
Column 7:  Value =   1.000000
Column 8:  Value =   0.000000
Column 9:  Value =   0.000000
Column 94:  Value =   4.000000
[3, 4, 6, 8]
[[ 4 10  9  1  8  6  3  2  5  7]
 [ 1  4  7  3  2  6  5  9 10  8]
 [ 5  7  3  8 10  1  6  9  2  4]
 [ 7  1  4  5  9  2  3 10  6  8]
 [ 2  4  7  6  3 10  9  5  1  8]
 [ 9  3  2  8 10  7  6  4  5  1]
 [10  4  2  1  5  3  7  9  8  6]
 [10  8  3  2  6  1  5  9  7  4]
 [ 7  3  2 10  9  1  5  8  4  6]
 [ 3  8  9  6 10  2  4  7  1  5]
 [ 3  6  5 10  2  8  9  1  7  4]]
CPXPARAM_Read_DataCheck                          1
CPXPARAM_Read_APIEncoding                        "UTF-8"
CPXPARAM_MIP_Strategy_CallbackReducedLP          0
Warning:  Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 14 rows and 0 columns.
Aggregator did 11 substitutions.
Reduced MIP has 571 rows, 77 columns, and 3206 nonzeros.
Reduced MIP has 76 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.50 ticks)
Found incumbent of value 6.000000 after 0.01 sec. (3.97 ticks)
Probing fixed 11 vars, tightened 0 bounds.
Probing time = 0.01 sec. (6.30 ticks)
Cover probing fixed 0 vars, tightened 5 bounds.
Tried aggregator 1 time.
MIP Presolve eliminated 113 rows and 16 columns.
Reduced MIP has 458 rows, 61 columns, and 2885 nonzeros.
Reduced MIP has 60 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.66 ticks)
Probing fixed 7 vars, tightened 0 bounds.
Probing time = 0.01 sec. (3.85 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 49 rows and 8 columns.
Reduced MIP has 409 rows, 53 columns, and 2690 nonzeros.
Reduced MIP has 52 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (3.31 ticks)
Probing time = 0.00 sec. (2.55 ticks)
Clique table members: 817.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.88 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                            6.0000        1.0000            83.33%
*     0+    0                            5.0000        1.0000            80.00%
      0     0        2.5455    13        5.0000        2.5455       20   49.09%
*     0+    0                            4.0000        2.5455            36.36%
      0     0        2.8133    14        4.0000      Cuts: 12       32   29.67%
      0     0        2.8996    12        4.0000      Cuts: 10       39   27.51%
      0     0        2.9155    13        4.0000      Cuts: 14       42   27.11%
      0     0        2.9180    13        4.0000      Cuts: 10       44   27.05%
      0     0        2.9300    14        4.0000      Cuts: 13       47   26.75%
      0     0        2.9304    15        4.0000    MIRcuts: 5       50   26.74%
      0     0        2.9308    16        4.0000      Cuts: 14       53   26.73%
      0     0        2.9331    15        4.0000       Cuts: 9       57   26.67%
*     0+    0                            4.0000        2.9331            26.67%
      0     0        cutoff              4.0000        4.0000       59    0.00%
Elapsed time = 0.19 sec. (60.14 ticks, tree = 0.01 MB, solutions = 4)

Clique cuts applied:  2
Mixed integer rounding cuts applied:  4
Zero-half cuts applied:  5
Lift and project cuts applied:  1
Gomory fractional cuts applied:  2

Root node processing (before b&c):
  Real time             =    0.20 sec. (60.16 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.20 sec. (60.16 ticks)

Solution status =  101 : MIP_optimal
Solution value  =  3.999999999
Column 0:  Value =   0.000000
Column 1:  Value =   0.000000
Column 2:  Value =   1.000000
Column 3:  Value =   0.000000
Column 4:  Value =   1.000000
Column 5:  Value =   0.000000
Column 6:  Value =   1.000000
Column 7:  Value =   0.000000
Column 8:  Value =   0.000000
Column 9:  Value =   1.000000
Column 87:  Value =   4.000000
[1, 3, 5, 7, 10]

In [35]:
selected_points = list((np.array(np.where(np.array(choices)>0.0))+1)[0])
selected_points


Out[35]:
[1, 2, 3, 8, 9]

In [197]:
matlab = np.loadtxt('../nisarg_code/testmatrix', delimiter=',')

In [198]:
print(matlab)


[[ 0.  1.  0. ...,  0.  0.  0.]
 [ 0. -1.  0. ...,  0.  0.  0.]
 [ 0.  1.  0. ...,  0.  0.  0.]
 ..., 
 [ 0.  0.  0. ...,  0.  0. -1.]
 [ 0.  0.  0. ...,  0.  0. -1.]
 [ 0.  0.  0. ...,  0.  0. -1.]]

In [226]:
print(Aineq)


[[ 0.  1.  0. ...,  0.  0.  0.]
 [ 0. -1.  0. ...,  0.  0.  0.]
 [ 0.  1.  0. ...,  0.  0.  0.]
 ..., 
 [ 0.  0.  0. ...,  0.  0. -1.]
 [ 0.  0.  0. ...,  0.  0. -1.]
 [ 0.  0.  0. ...,  0.  0. -1.]]

In [49]:
with open('./q2_sort_profile.p','rb') as file_:
    profile = pickle.load(file_)
profile.astype(np.int64)


Out[49]:
array([[ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [10, 10, 10,  0,  0,  0,  0,  0, 10, 10],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [10, 10,  0,  0, 10, 10,  0,  0, 10,  0],
       [10,  0,  0,  0, 10,  0,  0, 10, 10, 10],
       [ 0,  0,  0,  0, 10, 10, 10, 10, 10,  0],
       [ 0,  0,  0,  0, 10, 10, 10, 10, 10,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [10, 10, 10,  0,  0,  0, 10,  0, 10,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0]])

In [56]:
p


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-56-9d7bf0753729> in <module>()
----> 1 p

NameError: name 'p' is not defined

In [ ]: