From: Ashok on
Hi, I have been working on a problem for sometime now and have not been successful.
I need to maximize a particular function under non-linear constraints. I am using fmincon for this purpose. The procedure followed is as below, and have the file names same as what I have been using.

Script (*.m)->
1. OPTIMIZE: this initializes the corresponding values and executes the fmincon function.
This starts with a lower_bound of 1 each in a 4-tuple vector, x.
2. CONSTRAINT: this takes in some global values along with the vector x, and evaluates the
non-linear constraint.
3. MARKOV_MODEL: this function takes in the passed in vector, x, and dynamically
generates and executes MARKOV_CHAIN.m to determine the value of performance
that needs to be maximized.

Objective is to maximize the performance under the given constraints. The problem I am facing is that since I am generating a new file and then executing it to determine the performance the iterations stop if the constraints have been met but the value has not been maximized. I intend to carry on with iterations such that at a later value of the vector x the performance gets maximized and the constraint is achieved
Please help me figure out an alternative approach to do this. I am generating the file MARKOV_CHAIN.m since the concerned Markov chain equations change with the change in the values of the vector x and in turn the state space changes too. Basically this file contains the discrete markov chain analysis of the state space based on the vector x.
From: Matt J on
"Ashok " <hunt_ashok(a)yahoo.com> wrote in message <i3aevd$fqo$1(a)fred.mathworks.com>...

>
> Objective is to maximize the performance under the given constraints. The problem I am facing is that since I am generating a new file and then executing it to determine the performance the iterations stop if the constraints have been met but the value has not been maximized.
=================

It's not clear why you think generating an mfile file on-the-fly causes the premature stopping. Maybe it has to do with you not issuing a rehash() command after regenerating the file. Otherwise, I think it should work.

In any case, I want to emphasize that making dynamic changes to mfiles is a bad thing, and it's not clear why you find it necessary.



> I intend to carry on with iterations such that at a later value of the vector x the performance gets maximized and the constraint is achieved
==============

Incidentally, are you taking into account the fact that fmincon is a minimizer, rather than a maximizer?


> Please help me figure out an alternative approach to do this. I am generating the file MARKOV_CHAIN.m since the concerned Markov chain equations change with the change in the values of the vector x and in turn the state space changes too.
============

Still not clear why this requires a dynamically changing mfile. Who cares whether the state space changes with x? Why can't MARKOV_CHAIN.m be written as a standard function that takes x as input, derives a state space from x in an intermediate calculation, and returns an objective function value as its final result?
From: Ashok on
Matt,

Thanks for responding.
1. I am using fmincon to minimize a negative performance value, which works as a maximizer.
2. I am not aware of the rehash() function. Will look up some information and try to incorporate it. If possible may you please share some hints.
3. I am generating a different .m file dynamically since generating state space on the fly was felt complicated. So, I take in the corresponding vector and print the required equations in a different file and then execute it. This function returns the objective function result which is a negative value and needs to be maximized.

The iterations do not stop at the first step. It runs through few iterations and then as soon as the constraint is met the execution terminates, although the objective function is not maximized.
From: Ashok on
Also forgot to mention that the Markov_Chain.m first executes the "solve" function to solve as many linear equations as the state space generated by the vector x. Writing this function on-the-fly, without generating the new file, was felt impossible. This is one of the vital reasons for me to choose generating a new file and then executing it.
From: Matt J on
"Ashok " <hunt_ashok(a)yahoo.com> wrote in message <i3aisf$h8l$1(a)fred.mathworks.com>...

> 2. I am not aware of the rehash() function. Will look up some information and try to incorporate it. If possible may you please share some hints.
====

When MATLAB runs, it locks all mfiles in memory. Changes to files at run time will not be felt. However, REHASH forces MATLAB to recache all the mfiles, so it's probably what you need to override this behavior. See "help rehash" for more info.

> 3. I am generating a different .m file dynamically since generating state space on the fly was felt complicated. So, I take in the corresponding vector and print the required equations in a different file and then execute it.
......
Also forgot to mention that the Markov_Chain.m first executes the "solve" function to solve as many linear equations as the state space generated by the vector x. Writing this function on-the-fly, without generating the new file, was felt impossible. This is one of the vital reasons for me to choose generating a new file and then executing it.
===========

That only confuses me more. Setting up and solving linear equations is one of the easiest things for MATLAB. It's what MATLAB does best. It also baffles me that you are using the symbolic solve() function to deal with linear equations when MATLAB has excellent (and probably much more efficient) non-symbolic linear algebra tools for doing this.


> The iterations do not stop at the first step. It runs through few iterations and then as soon as the constraint is met the execution terminates, although the objective function is not maximized.
================

Well, if you're not using rehash(), fmincon is using the pre-runtime version of Markov_Chain.m over and over. One can imagine that causing problems.

It's also not clear if your objective function is differentiable. fmincon is only designed for differentiable objective functions.