#optional: 1st derivatives df = lambda x: 2*(x-5.45) # start point x0 = 8*cos(arange(N)) # assign prob: # 1st arg - objective function # 2nd arg - start point # for more details see # http://openopt.org/Assignment p = MINLP(f, x0, df=df, maxIter = 1e3) # optional: set some box constraints lb <= x <= ub p.lb = [-6.5]*N p.ub = [6.5]*N # see help(NLP) for handling of other constraints: # Ax<=b, Aeq x = beq, c(x) <= 0, h(x) = 0 # see also /examples/nlp_1.py # required tolerance for smooth constraints, default 1e-6 p.contol = 1.1e-6 p.name = 'minlp_1' # required field: nlpSolver - should be capable of handling box-bounds at least #nlpSolver = 'ralg' nlpSolver = 'ipopt' # coords of discrete variables and sets of allowed values p.discreteVars = {7:range(3, 10), 8:range(3, 10), 9:[2, 3.1, 9]}
new_ineq_vec = vstack( (ineq_constraint_matrix, -1 * equal_constraint_matrix)).tocsr() objective = lambda x: objective_helper(phi_mat * x, number_captains=number_captains) ineq_constraint = lambda x: ineq_matrix * x - ineq_constraint_matrix equal_constraint = lambda x: equal_matrix * (sts_mat * x ) - equal_constraint_matrix new_ineq_constraint = lambda x: new_ineq_mat * x - new_ineq_vec #print (new_ineq_mat * x)[-72:] #print new_ineq_vec.shape #t1 = equal_matrix * np.matrix(np.zeros(len(x))).T - equal_constraint_matrix #equal_constraint(np.matrix(np.zeros(len(x))).T) # test the equality constraint...something fishy is going on #p = MINLP(f = objective, x0 = np.matrix(np.zeros(len(x))).T, c = ineq_constraint, h = equal_constraint) p = MINLP(f=objective, x0=x, c=ineq_constraint, h=equal_constraint) #p = MINLP(f = objective, x0 = x, c = new_ineq_constraint) #p = MINLP(f = objective, x0 = x, A = ineq_matrix, b = ineq_constraint_matrix) p.discreteVars = mm.build_dictionary(number_captains) nlpSolver = 'ipopt' p.lb = [0] * len(x) p.ub = [1] * len(x) #r = p.solve('branb', nlpSolver = nlpSolver, plot = False)
N = 150 K = 50 #objective function: f = lambda x: ((x-5.45)**2).sum() #optional: 1st derivatives df = lambda x: 2*(x-5.45) # start point x0 = 8*cos(arange(N)) p = MINLP(f, x0, df=df, maxIter = 1e3) # optional: set some box constraints lb <= x <= ub p.lb = [-6.5]*N p.ub = [6.5]*N # see help(NLP) for handling of other constraints: # Ax<=b, Aeq x = beq, c(x) <= 0, h(x) = 0 # see also /examples/nlp_1.py # required tolerance for smooth constraints, default 1e-6 p.contol = 1.1e-6 p.name = 'minlp_1' nlpSolver = 'ipopt' # coords of discrete variables and sets of allowed values p.discreteVars = {7:range(3, 10), 8:range(3, 10), 9:[2, 3.1, 9]} # required tolerance for discrete variables, default 10^-5 p.discrtol = 1.1e-5