Thread: Want to use algorithm !

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    17

    Want to use algorithm !

    Hi there
    I want to apply Hooke and Jeeves algorithms on some values I have.
    I've googled and I found some Libraries and Source code files but I can't use them may be because of the compiler. (I tried VS 2005 and VS 6 pro).

    what do you suggest I should do ?
    just guide me to the right place to look at.

    I posted this here because I prefer the code to be in C++ as I want to transfer values from files to functions and then save them in new files.
    and I'll write this code in C++.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Try on this nice little site. If you get C source code, shouldn't be a big issue to change the code to C++ one step at a time. The algorithms are not that big.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    yea i've been there and that led me to netlib
    got the file
    couldn't get it to compile. :s
    got 16 errors and some warnings in VS 2005
    and 4 Errors in VS 6
    may be you can help me with errors
    this is on VS 6
    'x' : undeclared identifier
    : error C2065: 'n' : undeclared identifier
    : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
    : fatal error C1004: unexpected end of file found

    they are all in this function
    I think you need to take a look at the whole thing, right ?
    Can I upload it here ?
    Code:
    /* Rosenbrocks classic parabolic valley ("banana") function */
    double
    f(x, n)
    	   double	   x[VARS];
    	   int		   n;
    {
    	   double	   a, b, c;
    	   funevals++;
    	   a = x[0];
    	   b = x[1];
    	   c = 100.0 * (b - (a * a)) * (b - (a * a));
    	   return (c + ((1.0 - a) * (1.0 - a)));
    }
    EDIT: ok somehow I got around these errors but now it gives me another 4 Errors in another function.
    I noticed that most of them are undeclared identifier as he declares the variables(arguments) inside the function.
    can you help me with this?
    Last edited by Shady; 09-29-2006 at 05:15 PM.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >double
    >f(x, n)
    > double x[VARS];
    > int n;
    Why don't you change these four lines to:
    Code:
    double f(double x[VARS], int n)
    And try recompiling.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    Quote Originally Posted by swoopy
    >double
    >f(x, n)
    > double x[VARS];
    > int n;
    Why don't you change these four lines to:
    Code:
    double f(double x[VARS], int n)
    And try recompiling.
    that's exactly what I did.
    see my edited post
    oh and what about the other 2 errors ?

    EDIT: it's getting really messy.... I correct the errors and new ones pop up.
    it said about this
    z[i] = point[i] + delta[i];
    error C2109: subscript requires array or pointer type
    so I made them pointers.
    now it says
    error C2440: '=' : cannot convert from 'double' to 'double *'
    Last edited by Shady; 09-29-2006 at 05:23 PM.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Hmm... you should go back to their declarations and change only the one(s) that need to be changed. Regardless, post us the link to the code please
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    OK here's the link
    http://www.netlib.org/opt/hooke.c

    It will help me a lot if I got this code or any other to work.
    Thanks for helping.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > z[i] = point[i] + delta[i];
    Now that you've posted the code, those are already arrays:
    Code:
    	   double	   delta[VARS], point[VARS];
    	   double	   prevbest;
    	   int		   nvars;
    {
    	   double	   z[VARS];
    Hopefully you changed the beginning of the function (and any other functions) to look like this:
    Code:
    double best_nearby(double delta[VARS], double point[VARS], double prevbest, int nvars)
    {
    	   double	   z[VARS];
    	   double	   minf, ftmp;

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    OK someone please tell me what happened because one of us is stupid me or VS2005
    I create a new project Win32 Console Application, Empty project add new item to source file copy the code from notepad and paste it there .... I compile..... i get these errors that I posted.

    Now I do the same thing but I add an existing item which is the SAME CODE .... it compiles and runs no problems !!!!

    what happened ???????

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM