Пример #1
0
print("Evaluate f at x=", x)
print("f(x)=", objectiveFun(x))
print("g(x)=", constraintFun(x))

# Define problem
problem = ot.OptimizationProblem(objectiveFun)
problem.setInequalityConstraint(constraintFun)
bounds = ot.Interval([0., 0., 0., 0.], [1., 1., 1., 1.])
problem.setBounds(bounds)
problem.setMinimization(True)
problem.setVariablesType([ot.OptimizationProblemImplementation.BINARY, ot.OptimizationProblemImplementation.BINARY,
                          ot.OptimizationProblemImplementation.BINARY, ot.OptimizationProblemImplementation.BINARY])

# Define OptimizationAlgorithm
x0 = [0., 0., 0., 0.]
algo = ot.Bonmin(problem, "B-BB")
algo.setStartingPoint(x0)
algo.setMaximumEvaluationNumber(10000)
algo.setMaximumIterationNumber(1000)
ot.ResourceMap.AddAsScalar('Bonmin-bonmin.time_limit', 60)
algo.run()

# Retrieve result
result = algo.getResult()
x_star = result.getOptimalPoint()
print("x*=", x_star)
y_star = result.getOptimalValue()
neval = result.getEvaluationNumber()
print("f(x*)=", y_star, "neval=", neval)

print("g(x*)=", constraintFun(x_star))
Пример #2
0
# Definition of variables types
variablesType = [
    ot.OptimizationProblemImplementation.BINARY,
    ot.OptimizationProblemImplementation.CONTINUOUS,
    ot.OptimizationProblemImplementation.CONTINUOUS,
    ot.OptimizationProblemImplementation.INTEGER
]

# Setting up Bonmin problem
problem = ot.OptimizationProblem(objectiveFunction)
problem.setBounds(bounds)
problem.setVariablesType(variablesType)
problem.setInequalityConstraint(h)

bonminAlgorithm = ot.Bonmin(problem, 'B-BB')
bonminAlgorithm.setStartingPoint([0, 0, 0, 0])
bonminAlgorithm.setMaximumEvaluationNumber(10000)
bonminAlgorithm.setProgressCallback(progress)
bonminAlgorithm.setStopCallback(stop)

ot.ResourceMap.AddAsScalar('Bonmin-bonmin.time_limit', 60)
ot.ResourceMap.AddAsString('Bonmin-mu_oracle', 'loqo')

algos = ot.Bonmin.GetAlgorithmNames()

for algo in algos:
    if algo != "B-iFP":  # Solver B-iFP fails to terminate on this case
        print("MINIMIZATION WITH " + algo)
        bonminAlgorithm.setAlgorithmName(algo)
        bonminAlgorithm.run()