Main Content

La traducción de esta página aún no se ha actualizado a la versión más reciente. Haga clic aquí para ver la última versión en inglés.

Obtener una solución utilizando el modo de factibilidad

Este ejemplo muestra cómo utilizar el modo de factibilidad del algoritmo fmincon 'interior-point' para obtener un punto factible. Para aprovechar la diferenciación automática, el ejemplo utiliza el enfoque basado en problemas. El ejemplo se ha tomado del problema 9 de Moré [1].

Configuración del problema

El problema cuenta con una variable de optimización en 5D x junto con cinco restricciones cuadráticas. El primer componente de x tiene un límite inferior de 0 y los cuatro componentes restantes tienen límites superiores de 0.

x = optimvar("x",5,"LowerBound",[0;-Inf;-Inf;-Inf;-Inf],"UpperBound",[Inf;0;0;0;0]);

El problema, que procede del sector de la aviación, utiliza términos aeronáuticos para los componentes de x y ha especificado los valores de algunos parámetros.

elevator = 0.1; % If elevator were 0, then [0 0 0 0 0] would be a solution
aileron = 0.0;
rudderdf = 0.0;
rollrate = x(1);
pitchrat = x(2);
yawrate = x(3);
attckang = x(4);
sslipang = x(5);

Cree un problema de optimización y las restricciones.

prob = optimproblem;
prob.Constraints.eq1 = (-3.933*rollrate + 0.107*pitchrat + ...
    0.126*yawrate - 9.99*sslipang - 45.83*aileron - 7.64*rudderdf - ...
    0.727*pitchrat*yawrate + 8.39*yawrate*attckang - ...
    684.4*attckang*sslipang + 63.5*pitchrat*attckang) == 0;
prob.Constraints.eq2 = (-0.987*pitchrat - 22.95*attckang - ...
    28.37*elevator + 0.949*rollrate*yawrate + 0.173*rollrate*sslipang) == 0;
prob.Constraints.eq3 = (0.002*rollrate - 0.235*yawrate + ...
    5.67*sslipang - 0.921*aileron - 6.51*rudderdf - ...
    0.716*rollrate*pitchrat - 1.578*rollrate*attckang + ...
    1.132*pitchrat*attckang) == 0;
prob.Constraints.eq4 = (pitchrat - attckang - ...
    1.168*elevator - rollrate*sslipang) == 0;
prob.Constraints.eq5 = (-yawrate - 0.196*sslipang - ...
    0.0071*aileron + rollrate*attckang) == 0;

Este problema no tiene función objetivo, así que no especifique prob.Objective.

Intentar buscar una solución sin modo de factibilidad

Intente solucionar el problema utilizando el solver y los parámetros predeterminados, comenzando desde el punto [0 0 0 0 0]'.

x0.x = zeros(5,1);
[sol,~,exitflag,output] = solve(prob,x0)
Solving problem using fmincon.

Solver stopped prematurely.

fmincon stopped because it exceeded the iteration limit,
options.MaxIterations = 1.000000e+03.
sol = struct with fields:
    x: [5x1 double]

exitflag = 
    SolverLimitExceeded

output = struct with fields:
              iterations: 1000
               funcCount: 1003
         constrviolation: 11.1712
                stepsize: 8.2265e-05
               algorithm: 'interior-point'
           firstorderopt: 0
            cgiterations: 0
                 message: 'Solver stopped prematurely....'
            bestfeasible: []
     objectivederivative: "closed-form"
    constraintderivative: "closed-form"
                  solver: 'fmincon'

El solver se detiene prematuramente. Aumente el límite de iteraciones y el límite de evaluaciones de función y, después, inténtelo de nuevo.

options = optimoptions("fmincon","MaxIterations",1e4,"MaxFunctionEvaluations",1e4);
[sol,~,exitflag,output] = solve(prob,x0,"Options",options)
Solving problem using fmincon.

Converged to an infeasible point.

fmincon stopped because the size of the current step is less than
the value of the step size tolerance but constraints are not
satisfied to within the value of the constraint tolerance.


Consider enabling the interior point method feasibility mode.
sol = struct with fields:
    x: [5x1 double]

exitflag = 
    NoFeasiblePointFound

output = struct with fields:
              iterations: 4089
               funcCount: 4092
         constrviolation: 5.0899
                stepsize: 5.9783e-11
               algorithm: 'interior-point'
           firstorderopt: 0
            cgiterations: 0
                 message: 'Converged to an infeasible point....'
            bestfeasible: []
     objectivederivative: "closed-form"
    constraintderivative: "closed-form"
                  solver: 'fmincon'

El solver converge a un punto no factible.

Resolver utilizando el modo de factibilidad

Intente resolver el problema de nuevo y, esta vez, especifique las opciones EnableFeasibilityMode y SubproblemAlgorithm. Por lo general, si necesita utilizar el modo de factibilidad, la mejor forma es establecer la opción SubproblemAlgorithm en 'cg'.

options = optimoptions(options,"EnableFeasibilityMode",true,...
    "SubproblemAlgorithm","cg");
[sol,~,exitflag,output] = solve(prob,x0,"Options",options)
Solving problem using fmincon.

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
sol = struct with fields:
    x: [5x1 double]

exitflag = 
    OptimalSolution

output = struct with fields:
              iterations: 138
               funcCount: 139
         constrviolation: 2.9068e-04
                stepsize: 0.0057
               algorithm: 'interior-point'
           firstorderopt: 0
            cgiterations: 0
                 message: 'Local minimum found that satisfies the constraints....'
            bestfeasible: []
     objectivederivative: "closed-form"
    constraintderivative: "closed-form"
                  solver: 'fmincon'

Esta vez, el solver informa de que llega a una solución factible. No obstante, la vulneración de restricciones de output.constrviolation no es muy pequeña. Ajuste la tolerancia de restricción y resuélvalo de nuevo. Para acelerar el proceso de solución, comience desde la solución factible devuelta.

options.ConstraintTolerance = 1e-8;
[sol,~,exitflag,output] = solve(prob,sol,"Options",options)
Solving problem using fmincon.

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
sol = struct with fields:
    x: [5x1 double]

exitflag = 
    OptimalSolution

output = struct with fields:
              iterations: 2
               funcCount: 3
         constrviolation: 4.4409e-16
                stepsize: 1.7081e-08
               algorithm: 'interior-point'
           firstorderopt: 0
            cgiterations: 0
                 message: 'Local minimum found that satisfies the constraints....'
            bestfeasible: [1x1 struct]
     objectivederivative: "closed-form"
    constraintderivative: "closed-form"
                  solver: 'fmincon'

Ahora la vulneración de restricciones es bastante pequeña. El solver solo necesita dos iteraciones para llegar a esta solución mejorada.

Referencias

[1] Moré, J. J. A collection of nonlinear model problems. Proceedings of the AMS-SIAM Summer Seminar on the Computational Solution of Nonlinear Systems of Equations, Colorado, 1988. Argonne National Laboratory MCS-P60-0289, 1989.

Consulte también

|

Temas relacionados