Re: Constrained Optimization Algorithm
- From: muse <misiak.martin@xxxxxxxxxxxxxx>
- Date: Sun, 24 Aug 2008 10:53:36 -0700 (PDT)
On 22 Sie, 21:28, cyc1...@xxxxxxxxx wrote:
Hi all,
I am facing the following Optimization problem. I'll post an example
with a simple case.
I have 2 variables, x and y.
I want to maximize (f(x) + g(y))/2 while keeping x + y <= 10.
I know this is a NLP problem.
I have tried to use the Newton-Raphson algorithm but I dont' like it
because it highly depends on the initial chosen point.
I'll eventually have to expand this problem to thousands of variables
(as opposed to having only 2 variables: x and y).
Anyone know which I NLP algorithm I should use and where I can find
resources about that particular algorithm?
Thanks
you can use one of the standard algorithms described in chapter 10 of
the book: 'Numerical Recipies in C' by Press, Teukolsky available at:
http://www.nrbook.com/a/bookcpdf.php
but i would like to encourage you to try to use genetic algorithm.
I made simple case when you try to find the curve of minimal length
between two points, that is find the variables x_1,...x_n such that
x_1^2+...+x_n^2 is minimal. The code for 20 variables which find the
solution quite fast, in free pascal compiler is:
program mutation;
uses crt,graph;
var x:array[1..20] of integer;
gd,gm,i:integer;
n:int64;
s1,s2:double;
st:string;
begin
randomize;
DetectGraph(gd,gm);
InitGraph(gd,gm,' ');
x[1]:=1; x[20]:=20;
for i:=2 to 19 do
x[i]:=-5+random(40); //individual x_i with random 'genes'
repeat
ClearDevice;
for i:=1 to 20 do
putpixel(10*i+50,10*x[i]+50,red);
Str(n:8,st); Outtextxy(250,150,st);
delay(100);
i:=2+random(18); //mutation +
s1:=(x[i]-x[i-1])*(x[i]-x[i-1])+(x[i+1]-x[i])*(x[i+1]-x[i]);
//you need to evaluate the lenght of the curve only in the mutation
point!
s2:=(x[i]+1-x[i-1])*(x[i]+1-x[i-1])+(x[i+1]-x[i]-1)*(x[i+1]-x[i]-1);
if s2<=s1 then
x[i]:=x[i]+1;
i:=2+random(18); //mutation -
s1:=(x[i]-x[i-1])*(x[i]-x[i-1])+(x[i+1]-x[i])*(x[i+1]-x[i]);
s2:=(x[i]-1-x[i-1])*(x[i]-1-x[i-1])+(x[i+1]-x[i]+1)*(x[i+1]-x[i]+1);
if s2<=s1 then
x[i]:=x[i]-1;
n:=n+1;
until keypressed;
CloseGraph;
end.
Regards,
Martin, Poland
.
- References:
- Constrained Optimization Algorithm
- From: cyc1120
- Constrained Optimization Algorithm
- Prev by Date: Re: constrained quadratic optimization
- Next by Date: Re: constrained quadratic optimization
- Previous by thread: Constrained Optimization Algorithm
- Next by thread: Open sounce FDTD electromagnetic simulation codes in Java now available
- Index(es):
Relevant Pages
|