Exemplo n.º 1
0
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]}

# required tolerance for discrete variables, default 10^-5
p.discrtol = 1.1e-5

#optional: check derivatives, you could use p.checkdc(), p.checkdh() for constraints
#p.checkdf()

# optional: maxTime, maxCPUTime
# p.maxTime = 15
# p.maxCPUTime = 15

r = p.solve('branb', nlpSolver=nlpSolver, plot = False)
# optim point and value are r.xf and r.ff,
# see http://openopt.org/OOFrameworkDoc#Result_structure for more details
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
# 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

#optional: check derivatives, you could use p.checkdc(), p.checkdh() for constraints
#p.checkdf()

# optional: maxTime, maxCPUTime
# p.maxTime = 15
# p.maxCPUTime = 15

r = p.solve('branb', nlpSolver=nlpSolver, plot = False)
# optim point and value are r.xf and r.ff,
# see http://openopt.org/OOFrameworkDoc#Result_structure for more details
#