How to create a function that computes its (initialized) parameters only once?

What is the general technique to perform pre-computation (to compute some fixed parameters) only once? In my instance, for example, I am solving a large Mixed Integer Linear using intlinprog, but I do not want to "construct" the "non-changing" parts of the optimization problem (some part of f,intcon,A,b,Aeq,beq,lb,ub,options). That is, I want to write a function that calls a intlinprog but I don't want to each time construct the parts of the parameters that do not depend on the input parameter.
Saving those parameters in a mat file and loading them is a work-around. But I am wondering whether there are better systematic ways, like using function handles, or object oriented programming can do better. Thanks!

1 comentario

jgg
jgg el 29 de Abr. de 2016
Editada: jgg el 29 de Abr. de 2016
I'm unclear what you are asking to do here. All of the values you pass to intlinprog do not change within the optimization problem. I'm assuming that you mean you're passing some of the options like Aeq beq lb ub but want to change some of them on the fly (like A and b).
The easiest way to do this is to, you you suggest, to use an anonymous function:
%compute intcon, Aeq, beq etc; the non-changing parts
intlin_res = @(A,b)(intlinprog(f,intcon,A,b,Aeq,beq));
You can do something similar in general.

Iniciar sesión para comentar.

Respuestas (0)

Productos

Etiquetas

Preguntada:

el 29 de Abr. de 2016

Editada:

jgg
el 29 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by