Constrained Optimization Problem in C

Discussion in 'C Programming' started by Explore_Imagination, Jan 2, 2008.

  1. The task is to solve a constrained optimization problem in C.
    Computational
    Time is of high priority. One approach can be to use ready functions
    in a "free ware" Optimization Library (if available). If any one of
    you have any idea about such library please inform me. I am dealing
    with Constrained Optimization for the first time so please guide me
    How I should solve this problem. I will appreciate suggestions from
    you.

    Find values of x that minimize f=-x1*x2*x3 and subject to the
    constraints:

    x1+2*x2+2*x3>0
    x1+2*x2+2*x3<72
    x2=10


    In Matlab it can be solved by:

    x0 = [10; 10; 10]; % Starting guess at the solution

    A=[]; b=[]; Aeq=[]; beq=[]; lb=[]; ub=[];

    [x,fval] = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@(x)constr(x))


    %myfun

    function f = myfun(x)

    f = -x(1)* x(2)* x(3); %f=-x1*x2*x3


    %constr

    function [c,ceq]=constr(x)

    c(1)=0-(x(1)+2*x(2)+2*x(3)); %x1+2*x2+2*x3>0

    c(2)=x(1)+2*x(2)+2*x(3)-72; %x1+2*x2+2*x3<72

    ceq(1)=x(2)-10; %x2=10

    Hoping to hear from you guys !!!!

    --
    /BR
    Hassan
     
    Explore_Imagination, Jan 2, 2008
    #1
    1. Advertising

  2. Explore_Imagination

    user923005 Guest

    On Jan 2, 1:44 pm, Explore_Imagination <>
    wrote:
    > The task is to solve a constrained optimization problem in C.
    > Computational
    > Time is of high priority. One approach can be to use ready functions
    > in a "free ware" Optimization Library (if available). If any one of
    > you have any idea about such library please inform me. I am dealing
    > with Constrained Optimization for the first time so please guide me
    > How I should solve this problem. I will appreciate suggestions from
    > you.
    >
    > Find values of x that minimize  f=-x1*x2*x3  and subject to the
    > constraints:
    >
    > x1+2*x2+2*x3>0
    > x1+2*x2+2*x3<72
    > x2=10
    >
    > In Matlab it can be solved by:
    >
    > x0 = [10; 10; 10];    % Starting guess at the solution
    >
    > A=[];  b=[];  Aeq=[]; beq=[];  lb=[];  ub=[];
    >
    > [x,fval] = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@(x)constr(x))
    >
    > %myfun
    >
    > function f = myfun(x)
    >
    > f = -x(1)* x(2)* x(3);        %f=-x1*x2*x3
    >
    > %constr
    >
    > function [c,ceq]=constr(x)
    >
    > c(1)=0-(x(1)+2*x(2)+2*x(3));   %x1+2*x2+2*x3>0
    >
    > c(2)=x(1)+2*x(2)+2*x(3)-72;     %x1+2*x2+2*x3<72
    >
    > ceq(1)=x(2)-10;                 %x2=10
    >
    > Hoping to  hear from you guys !!!!


    Go here:
    http://plato.asu.edu/cgi-bin/htsearch
    Type in search window "constrained optimization problem"

    You probably wanted news:sci.math.num-analysis because your question
    is not about the C language at all.
     
    user923005, Jan 2, 2008
    #2
    1. Advertising

  3. Explore_Imagination

    Eric Sosman Guest

    Explore_Imagination wrote:
    > The task is to solve a constrained optimization problem in C.
    > Computational
    > Time is of high priority. One approach can be to use ready functions
    > in a "free ware" Optimization Library (if available). If any one of
    > you have any idea about such library please inform me. I am dealing
    > with Constrained Optimization for the first time so please guide me
    > How I should solve this problem. I will appreciate suggestions from
    > you.
    >
    > Find values of x that minimize f=-x1*x2*x3 and subject to the
    > constraints:
    >
    > x1+2*x2+2*x3>0
    > x1+2*x2+2*x3<72
    > x2=10
    >
    >
    > In Matlab it can be solved by:
    > [...]


    With pencil and paper it can be solved in less time
    than it took to compose the query. There are only two
    variables, the objective function is the negated product
    of those two variables, and the feasible region is bounded
    by two parallel lines. By inspection, the minimum must
    occur when the two variables have the same sign (the point
    (0,0) is in the feasible region, so the minimum cannot be
    positive). The minimum therefore occurs somewhere on the
    boundary of the butterfly-shaped region consisting of a
    triangle in each of the first and third quadrants. It
    cannot be anywhere along the axes (the product there is
    zero), so it must be somewhere on one of the hypotenuses.
    The first-quadrant triangle's hypotenuse is farther from
    the origin, so the product there must be larger than that
    along the third-quarter hypotenuse. Time for a tiny bit of
    calculus to find one derivative, and Bingo!

    Are you killing canaries with cannon, or massacring
    magpies with Matlab?

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jan 3, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cltsaig

    Port "arg" is not constrained?

    cltsaig, Oct 12, 2004, in forum: VHDL
    Replies:
    2
    Views:
    748
    cltsaig
    Oct 12, 2004
  2. Replies:
    9
    Views:
    8,103
    Ralf Hildebrandt
    Jan 19, 2005
  3. Explore_Imagination

    Constrained Optimization Problem in C++

    Explore_Imagination, Jan 2, 2008, in forum: C++
    Replies:
    6
    Views:
    3,158
    Kira Yamato
    Jan 3, 2008
  4. Replies:
    2
    Views:
    531
  5. Ravikiran

    Zero Optimization and Sign Optimization???

    Ravikiran, Nov 17, 2008, in forum: C Programming
    Replies:
    22
    Views:
    904
    Thad Smith
    Nov 24, 2008
Loading...

Share This Page