Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-02-2017
07:43 AM

50 Views

C# dtrnlspbc_init

I'm trying to understand how to declare and use in C#: RCI TR Routines for Problem with Bound Constraints.

I have created a simple test console program, and declared just one function (dtrnlspbc_init) but I receive that "there was an error in the input parameters".

It is a Marshalling problem, I suppose, but I don't understand where there is the error.

Is there someone that can help me?

Thankyou

Gianluca

Link Copied

10 Replies

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-02-2017
05:11 PM

50 Views

Check the second and third arguments to dtrnlspbc_init(). I believe that you have them interchanged.

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2017
12:26 AM

50 Views

Now it works! thank you

by the way the documentations it is not so clear.

Best Regards

Gianluca

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2017
02:55 PM

50 Views

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2017
07:42 PM

50 Views

Hi Thank you a lot for the reply mecej4.

Hi Gianluca,

You can take the second and third arguments are x length and F(x) length (or m - dimension of function value */.)

actually, the solver required m>>n.Where n is array X's size; m is *fvec *Array of size *m. So you may be change the m = xxx. when go to *solve step based on your fvec.

Best Regards,

Ying

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2017
11:57 PM

50 Views

If I read this page https://software.intel.com/en-us/node/471100#867C84A5-D029-4C48-B63B-B68E04CE043D,

n is the number of variables and, m is the number of functions. In my case I have n=5 and m=1 but this is not allowed because m >> n.

Maybe the parameter are swapped in the dtrnlspbc_init().

Best Regards

Gianluca

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-04-2017
02:42 AM

50 Views

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-06-2017
06:54 AM

50 Views

Thank you for your suggestions.

now it is more clear to me, by the way, I've implemented a test code like the example in the web page (https://software.intel.com/en-us/node/522321).

The objective_function is my_function().

The loop exited correctly but I can't understand where to find the solution!

check row code number 411.

What I miss?

Thank you very much

Gianluca

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-06-2017
03:56 PM

50 Views

The solution is in xres[], since you used Marshall.Copy to put it there. All that you have to do is to add a formatted output statement such as

Console.WriteLine(string.Format("{0:0.00} {1:0.00} {2:0.00} {3:0.00} {4:0.00}",

xres[0],xres[1],xres[2],xres[3],xres[4]));

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-06-2017
11:18 PM

50 Views

I'm sorry, maybe I was not clear ...

Do you really thought that after the Marshal.Copy(), I couldn't get the array values?

The problem is that the result it is not right!

I mean, these are the initial values. The solutions should be differents.

These should be the correct results:

0 = 197

1 = 351

2 = 185

3 = 1,7

4 = 8,8

We are sure of this, because we got it with another algoritms (Amoeba)

Thank you

Gianluca

Gianluca_G_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-07-2017
12:05 AM

50 Views

mecej4 i got the solution!

now it works ....

I forgot to copy the result with Marshal.Copy in my_function proc.

public static void my_function(ref int m, ref int n, [In] IntPtr xp, [Out] IntPtr fp) { double[] x = new double; Marshal.Copy(xp, x, 0, n); double[] f = new double ; Marshal.Copy(fp, f, 0, m); double rho1 = x[0]; double rho2 = x[1]; double rho3 = x[2]; double h1 = x[3]; double h2 = x[4]; //double phi = 0; //int iN = m; // mlMeasures.Count; //Da inserire for (int i = 0; i < m; i++) { f = Math.Pow((mlMeasures.RhoM - RhoCalc(mlMeasures.A, rho1, rho2, rho3, h1, h2)) / mlMeasures.RhoM, 2); } Marshal.Copy(f, 0, fp, m); }

Thank you very much

Gianluca

For more complete information about compiler optimizations, see our Optimization Notice.