forum.alglib.net
http://forum.alglib.net/

How to make functions depend on user input in minlmoptimize
http://forum.alglib.net/viewtopic.php?f=2&t=613
Page 1 of 1

Author:  Hansch [ Sat Sep 08, 2012 12:14 pm ]
Post subject:  How to make functions depend on user input in minlmoptimize

Hi.

I can't figure out if it's somehow possible to input/customize the functions to be minimized/optimized at runtime in C#.
Im making an application for economic students with a GUI. A basic thing in economics is the supply and demand curves. The students will for example see two curves and their intersection in a cordinate system. I use lmoptimize to calculate the intersection cordinates.

If the students want to change the demand or supply they can do it on the fly by moving a slider. If the demand curve is 1/x + 15 the student can change the demand by moving the curve upwards or downwards. If the user moves the demand curve upwards for example to 1/x + 17 I need to be able to recalculate the intersection between the supply and demand curve because it has changed. How can I do this on the fly?

In the example from the reference manual (example_minlm_d_v)

http://www.alglib.net/translator/man/ma ... _minlm_d_v

the function structure has to be "there" at compile time. In my program where minlmoptimize is used for calculating intersection it looks like this:


Code:
      public static void function1_fvec(double[] x, double[] fi, object obj)
        {


            fii[0] = (1 / x[0] + 15) - (x[1] - 16);
            fii[1] = (x[1] - 16) - (1 / x[0]+15);

        }


I would like to be able to change the fi function vector so the new intersection depending on the user input is calculated in real time. So the new functions in from above in this case would look like:

Code:
public static void function1_fvec(double[] x, double[] fi, object obj)
        {


            fii[0] = (1 / x[0] + 17) - (x[1] - 16);
            fii[1] = (x[1] - 16) - (1 / x[0]+17);

        }



It would be very nice if you could pass a string (or something) to and call the function1_fvec with the new user function each time he or she changed the slider. Is this possible to do or should I try to use the codedom compiler in C# which I don't have any experience in.

Thank you very much.

Greets

Hans

Author:  Sergey.Bochkanov [ Mon Sep 10, 2012 4:34 am ]
Post subject:  Re: How to make functions depend on user input in minlmoptim

There is an additional parameter obj which is passed to user-defined delegate. You can pass additional information by means of this parameter. For example, it may contain reference to structure which stores parameters of user-defined curve.

Author:  Hansch [ Tue Sep 11, 2012 9:14 am ]
Post subject:  Re: How to make functions depend on user input in minlmoptim

Sergey.Bochkanov wrote:
There is an additional parameter obj which is passed to user-defined delegate. You can pass additional information by means of this parameter. For example, it may contain reference to structure which stores parameters of user-defined curve.

Thanks a lot Sergey.

Ill try to figure it out. Im reading another post in forum I found after you told me about that.

viewtopic.php?f=2&t=386&hilit=passing+object

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/