Different ways to solve a problem based , non linear function (sum(K.^2) -K is a 20*1 matrix) problem with linear equality constrains and having binary, continuous variables

3 views (last 30 days)
I want to solve a minimization of non linear function .which contain variables are binary and continious , constrains are linear . when i run the program in matlab it is showing
Solving problem using ga.
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance
and constraint violation is less than options.ConstraintTolerance.
is there any other solve which can solve my problem rather than 'ga'? (with binary and continious variables)

Accepted Answer

John D'Errico
John D'Errico on 22 Apr 2023
None of the optimizers in the optimization toolbox (except for intlinprog, which handles only linear problems, so it does not apply) can handle mixed integer problems. Binary variables are a subset of integer variables, so that rules out most of the solvers. That leaves you with only the tools in the global optimization toolbox.
help globaloptim
Global Optimization Toolbox Version 4.8.1 (R2023a) 19-Nov-2022 Solvers ga - Genetic algorithm solver. gamultiobj - Multi-objective genetic algorithm solver. GlobalSearch - A scatter-search based global optimization solver. MultiStart - A multi-start global optimization solver. paretosearch - A patternsearch-based multi-objective solver. particleswarm - Particle swarm solver. patternsearch - Pattern search solver. simulannealbnd - Simulated annealing solver. surrogateopt - Surrogate optimization solver. Accessing options GlobalSearch - Get/set options for GlobalSearch solver. MultiStart - Get/set options for MultiStart solver. optimoptions - Create or alter optimization solver options. Live Editor task and plot functions. Optimize - Global Optimization Toolbox Live Editor task (available in the Live Editor only). Utility for GlobalSearch and MultiStart solvers createOptimProblem - Create an optimization problem. Start point sets for MultiStart solver CustomStartPointSet - A start point set that contains custom start points. RandomStartPointSet - A random start point set. Fitness scaling for genetic algorithm fitscalingshiftlinear - Offset and scale fitness to desired range. fitscalingprop - Proportional fitness scaling. fitscalingrank - Rank based fitness scaling. fitscalingtop - Top individuals reproduce equally. Selection for genetic algorithm selectionremainder - Remainder stochastic sampling without replacement. selectionroulette - Choose parents using roulette wheel. selectionstochunif - Choose parents using stochastic universal sampling (SUS). selectiontournament - Each parent is the best of a random set. selectionuniform - Choose parents at random. Crossover (recombination) functions for genetic algorithm. crossoverheuristic - Move from worst parent to slightly past best parent. crossoverintermediate - Weighted average of the parents. crossoverscattered - Position independent crossover function. crossoversinglepoint - Single point crossover. crossovertwopoint - Two point crossover. crossoverarithmetic - Arithmetic mean between two parents satisfying linear constraints and bound. Mutation functions for genetic algorithm mutationgaussian - Gaussian mutation. mutationuniform - Uniform multi-point mutation. mutationadaptfeasible - Adaptive mutation for linearly constrained problems. Distance function for multi-objective genetic algorithm distancecrowding - Calculates crowding distance for individuals Plot functions for genetic algorithm gaplotbestf - Plots the best score and the mean score. gaplotbestindiv - Plots the best individual in every generation as a bar plot. gaplotdistance - Plots average distance between some individuals. gaplotexpectation - Plots raw scores vs the expected number of offspring. gaplotgenealogy - Plot the ancestors of every individual. gaplotrange - Plots the min, mean, and max of the scores. gaplotscorediversity - Plots a histogram of this generations scores. gaplotscores - Plots the scores of every member of the population. gaplotselection - Plots a histogram of parents. gaplotstopping - Plots stopping criteria levels. gaplotmaxconstr - Plots maximum nonlinear constraint violation gaplotpareto - Plots Pareto front for a multi-objective GA gaplotparetodistance - Plots distance measure of individuals on Pareto front in multi-objective GA gaplotrankhist - Plots histogram of rank of the population gaplotspread - Plots spread of Pareto front in multi-objective GA Output functions for genetic algorithm gaoutputfile - Writes iteration history of the genetic algorithm solver to a file. gaoutputfcntemplate - Template file for a custom output function. Plot function for particle swarm optimization pswplotbestf - Plots best function value. Search methods for pattern search searchlhs - Implements Latin hypercube sampling as a search method. searchneldermead - Implements Nelder-Mead simplex method (FMINSEARCH) to use as a search method. searchga - Implements genetic algorithm (GA) to use as a search method. searchfcntemplate - Template file for a custom search method. Plot functions for pattern search psplotbestf - Plots best function value. psplotbestx - Plots current point in every iteration as a bar plot. psplotfuncount - Plots the number of function evaluation in every iteration. psplotmeshsize - Plots mesh size used in every iteration. psplotmaxconstr - Plots maximum nonlinear constraint violation Output functions for pattern search psoutputfile - Writes iteration history of the pattern search solver to a file. psoutputfcntemplate - Template file for a custom output function. Annealing functions for simulated annealing annealingboltz - Boltzman annealing. annealingfast - Fast annealing. saannealingfcntemplate - Template file to write annealing function. Acceptance functions for simulated annealing acceptancesa - Simulated annealing acceptance function. saacceptancefcntemplate - Template file to write acceptance function. Temperature functions for simulated annealing temperatureboltz - Boltzman annealing temperature function. temperatureexp - Exponential annealing temperature function. temperaturefast - Fast annealing temperature function. satemperaturefcntemplate - Template file to write temperature function. Plot functions for simulated annealing saplotbestf - Plots best function value. saplotbestx - Plots best point in every iteration as a bar plot. saplotf - Plots current function value. saplotx - Plots current point in every iteration as a bar plot. saplotstopping - Plots stopping criteria levels. saplottemperature - Plots mean temperature. Global Optimization Toolbox Documentation doc globaloptim Folders named globaloptim toolbox/globaloptim globaloptim/globaloptim
Of the solvers in that list of tools, besides GA, only SURROGATEOPT allows you to specify that some variables must be integer.
help surrogateopt
SURROGATEOPT The surrogateopt function is a global solver for time-consuming objective functions. surrogateopt attempts to solve problems of the form minimize f(x) subject to: lb <= x <= ub (bound constraints) A*X <= B, Aeq*X = Beq (linear constraints) c(x) <= 0 (nonlinear inequalities) x(i) must be integer for i in intcon The solver searches for the global minimum of a real-valued objective function in multiple dimensions, subject to bounds, optional integer constraints, and optional nonlinear inequality constraints. surrogateopt is best suited to objective functions that take a long time to evaluate. The objective function can be nonsmooth. The solver requires finite bounds on all variables. The solver can optionally maintain a checkpoint file to enable recovery from crashes or partial execution, or optimization continuation after meeting a stopping condition. x = SURROGATEOPT(fun,lb,ub) searches for a global minimum of fun(x) in the region lb <= x <= ub. fun accepts a single row vector argument x. fun can return either * a real scalar fval = fun(x), or * a structure. If the structure contains a field Fval, then surrogateopt attempts to minimize fun(x).Fval. If the structure contains a field Ineq, then surrogateopt attempts to make all of the components of that field be nonpositive: fun(x).Ineq <= 0 for all entries. For information on converting nonlinear constraints between the surrogateopt structure syntax and other solvers, see the packfcn function reference page. x = SURROGATEOPT(fun,lb,ub,intcon) requires that the variables listed in intcon take integer values. pass intcon = [] if there are no integer variables. x = SURROGATEOPT(fun,lb,ub,intcon,A,B) finds a local minimum x subject to the linear inequalities A*X <= B. x = SURROGATEOPT(fun,lb,ub,intcon,A,B,Aeq,Beq) finds a local minimum x subject to the linear equalities Aeq*X = Beq as well as A*X <= B. (Set A=[] and B=[] if no inequalities exist.) x = SURROGATEOPT(fun,lb,ub,intcon,A,B,Aeq,Beq,options) replaces the default optimization parameters by values in options. Create options using optimoptions. x = SURROGATEOPT(PROBLEM) searches for a minimum for PROBLEM, a structure with these fields: objective: The objective (and constraint) function lb: Lower bounds for x ub: Upper bounds for x intcon: Indices of variables that must be integer Aineq: <A matrix for inequality constraints> bineq: <B vector for inequality constraints> Aeq: <A matrix for equality constraints> beq: <B vector for equality constraints> rngstate: Optional field to reset the state of RNG options: Options created with OPTIMOPTIONS solver: 'surrogateopt' x = SURROGATEOPT(checkpointFile) continues running the optimization from the state in a saved checkpoint file. checkpointFile is a path to a checkpoint file, specified as a string or character vector. If you specify a file name without a path, SURROGATEOPT uses a checkpoint file in the current folder. SURROGATEOPT creates a checkpoint file when it has a valid CheckpointFile option. The data in a checkpoint file is in .mat format. To avoid errors or other unexpected results, do not modify the data before calling surrogateopt. x = SURROGATEOPT(checkpointFile,opts) continues running the optimization from the state in a saved checkpoint file, and replaces options in checkpointFile with those in opts. surrogateopt accepts changes in the following options: CheckpointFile Display MaxFunctionEvaluations MaxTime MinSurrogatePoints ObjectiveLimit OutputFcn PlotFcn UseParallel UseVectorized BatchUpdateInterval [x,fval] = SURROGATEOPT(__) also returns the best (smallest) value of the objective function found by the solver, using any of the input argument combinations in the previous syntaxes. [x,fval,exitflag] = SURROGATEOPT(__) also returns exitflag, an integer describing the reason the solver stopped. Possible values of exitflag and the corresponding exit conditions are listed below. 1 Best function value reached options.ObjectiveLimit 3 Feasible point but solver stopped (stalled) because no new points were found. 10 Unique solution exist for the problem due to one of the following reasons: All lower bounds are same as corresponding upper bounds. Unique solution due to linear equalities. 0 Number of function evaluations exceeded options.MaxFunctionEvaluations or elapsed time exceeded options.MaxTime. -1 Stopped by output/plot function. -2 No feasible point found due to one or more of the following reasons: One or more lower bound lb(i) exceeds a corresponding upper bound ub(i). One or more ceil(lb(i)) exceeds a corresponding floor(ub(i)) for i in INTCON. Linear constraints are infeasible. No solution found that satisfies nonlinear constraints. [x,fval,exitflag,output] = SURROGATEOPT(__) also returns output, a structure with these fields: rngstate: State of the random number generator before the solver started. funccount: Total number of function evaluations. message: Reason why SURROGATEOPT stopped. elapsedtime: Time spent running the solver in seconds, as measured by tic/toc. constrviolation: Maximum constraint violation due to nonlinear inequalities at x. ineq: Inequality constraints at the x. [x,fval,exitflag,output,trials] = SURROGATEOPT(__) also returns a structure containing all of the evaluated points (Npts) and the function function values at those points. trials have these fields: trials.X: Matrix of size Npts-by-Nvar. Each row of trials.X represents one point that SURROGATEOPT evaluated. trials.Fval: A vector, where each entry is the objective function value of the corresponding row of trials.X trials.Ineq: A matrix in which rows are nonlinear inequalties of the corresponding row of trials.X Examples: Find the minimum of a function subject to bounds. Search for a minimum of the six-hump camel back function in the region -2.1 <= x(i) <= 2.1. This function has two global minima with the objective function value -1.0316284... and four local minima with higher objective function values. fun = @(x)(4*x(:,1).^2 - 2.1*x(:,1).^4 + x(:,1).^6/3 ... + x(:,1).*x(:,2) - 4*x(:,2).^2 + 4*x(:,2).^4); lb = [-2.1,-2.1]; ub = -lb; x = surrogateopt(fun,lb,ub) Find the minimum of a function subject to nonlinear constraints. Find the minimum of Rosenbrock's function 100(x(2)-x(1)2)2+(1-x(1))2 subject to the nonlinear constraint that the solution lies in a disk of radius 1/3 around the point [1/3,1/3]: (x(1)-1/3)2+(x(2)-1/3)2 <= (1/3)2. To do so, write a function fun(x) that returns the value of Rosenbrock's function in a structure field Fval, and returns the nonlinear constraint value in the form c(x) <= 0 in the structure field Ineq. function f = fun(x) f.Fval = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2; f.Ineq = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2; Call surrogateopt using lower bounds of 0 on each component and upper bounds of 2/3. lb = [0,0]; ub = [2/3,2/3]; [x,fval,exitflag] = surrogateopt(@fun,lb,ub) If objective and constraints are in separate function use this convenienece function to return output as a struct. objAndConstr = packfcn(@objective,@inequalities) X = surrogateopt(objAndConstr, ...) % objAndConstr is a function handle Find the minimum of a function subject to integer constraints Find the minimum of the piecewiseFcn function for a two-dimensional variable x whose first component is restricted to integer values, and all components are between -5 and 5. function f = piecewiseFcn(x) f = zeros(1,size(x,1)); for i = 1:size(x,1) if x(i,1) < -5 f(i) = (x(i,1)+5)^2 + abs(x(i,2)); elseif x(i,1) < -3 f(i) = -2*sin(x(i,1)) + abs(x(i,2)); elseif x(i,1) < 0 f(i) = 0.5*x(i,1) + 2 + abs(x(i,2)); elseif x(i,1) >= 0 f(i) = .3*sqrt(x(i,1)) + 5/2 +abs(x(i,2)); end end intcon = 1; rng default % For reproducibility fun = @piecewiseFcn; lb = [-5,-5]; ub = [5,5]; x = surrogateopt(fun,lb,ub,intcon) Restart from checkpoint file To enable restarting surrogate optimization due to a crash or any other reason, set a checkpoint file name. Create an optimization problem and set a small number of function evaluations. rng default % For reproducibility fun = @(x)(4*x(:,1).^2 - 2.1*x(:,1).^4 + x(:,1).^6/3 ... + x(:,1).*x(:,2) - 4*x(:,2).^2 + 4*x(:,2).^4); lb = [-2.1,-2.1]; ub = -lb; opts = optimoptions('surrogateopt','CheckpointFile','checkfile.mat'); opts.MaxFunctionEvaluations = 30; [x,fval,exitflag,output] = surrogateopt(fun,lb,ub,opts) Set options to use 100 function evaluations (which means 70 more than already done) and restart the optimization. opts.MaxFunctionEvaluations = 100; [x2,fval2,exitflag2,output2] = surrogateopt('checkfile.mat',opts) See also OPTIMOPTIONS, PATTERNSEARCH, FMINCON Documentation for surrogateopt doc surrogateopt
  1 Comment
Jay Chandra
Jay Chandra on 24 Apr 2023
How can i change the same problem ( non linear function sum(k.^2) where k is a 20*1 matrix) to linear incase if i want to linearise ?

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!