Re: [eclipse-clp-users] API for c++ nolinear constraints

From: Kish Shen <kisshen_at_...5...>
Date: Mon, 24 Aug 2009 20:19:50 +0100
liu.yu.senior.china wrote:
> Dear Kish Shen,
> 
> Thank you so much for your reply. I have to use c++ API because the constants are actually known varables computed by my c++ code. And I need to fomulate the model hundreds of times in my code. So I have to use c++ API.
> 
This is not a reason to create the constraints in C++ -- you should pass 
the constants to ECLiPSe and generate the constraints there.

> I have read the manual for C++ API. It is kind of vague and not easily understood due to the lack of examples. Since I only have two kinds of constraints, can you give me a piece of code for each one?
> Do you know any other CLP to with well developed C++ interface?
>

There are examples of how to build ECLiPSe structures in the manual:

http://www.eclipse-clp.org/doc/embedding/embroot008.html#toc14

and there is an example in the doc/examples directory -- eg_sendmore.cc, 
which shows how to construct a (simple) finite domain program in C++.

You have not said what sort of constraints domain you are using. Also 
you mention CLP -- Constraint Logic Programming -- which by definition 
means Prolog based systems, and thus using C++ will not be the normal 
way of putting constraints into these systems. I assume you are asking 
about constraint solver libraries for C++. This will depend on what 
domain you are using -- if you are using integer finite domain, then 
there are both commercial and open-source solvers. I have some 
familiarity with Gecode (www.gecode.org), which is an open source 
constraint solver. In this case, complex non-linear expressions are not 
directly supported (as far as I know), and you need to decompose the 
constraint yourself into simpler constraints supported by the solver 
(this is what ECLiPSe's ic solver does for you, so you don't need to do 
it yourself).

If instead you are using real interval domain, then I don't know of any 
solver library for it.

Cheers,

Kish


> Thank you very much.
> 
> Best,
> 
> Liu,Yu
> 
> 
> 2009-08-24 
> 
> 
> 
> liu.yu.senior.china 
> 
> 
> 
> 发件人: Kish Shen 
> 发送时间: 2009-08-24  09:52:18 
> 收件人: liu.yu.senior.china 
> 抄送: eclipse-clp-users 
> 主题: Re: [eclipse-clp-users] API for c++ nolinear constraints 
>  
> Hi Liu Yu,
> ECLiPSe is a programming language, and you should write your program 
> (and thus the constraints you want to use) in ECLiPSe, and not try to do 
> it from C++. In ECLiPSe, you can write the expressions more or less like 
> you have presented them:
> C1/X1 =< R1
> (note =< is used instead of <=, as <= looks like implication)
> and to write this as a constraint, with X1 taking real values, you need 
> lib(ic), and use $=< for your operator:
> C1/X1 $=< R1
> liu.yu.senior.china wrote:
>> Dear Sir or Madam,
>>
>> I am new to eclipse and clp and I have nonlinear constraints as follows:
>>
>> only  x1..xn are vaiables and all the thers are constants.
>>
>> c1/x1<=r1
>> c1/x1+c2/x2<=r2
>> c1/x1+c2/x2+c3/x3<=r3
>> c1?x1+c2/x2+c3/x3+..+cn/xn<=rn
>>
>> I was wondering if I can use a single for loop to post all the constraints. Is there any eclipse data type for me to store expressions like c1/x1+c2/x2...?
>>
> Yes, in ECLiPSe you can write arbitrarily complex expressions without 
> any problems.
>> Another constraint is like
>>
>> exp(c1*x1)+exp(c2*x2)+...+exp(cn*xn)>=constant
> exp(Expr) (e to the power of Expr) is supported by lib(ic).
>> How can I build the above constraints using c++ API?
>>
> As stated before -- it is strongly recommended that you *do not* build 
> such complex data structures in C++. ECLiPSe is not designed to be a 
> constraint library for use with C++. If you want to do this, you are 
> probably better off using a different package that is designed for this.
> You should do your programming in ECLiPSe itself.
> The recommended way to use the ECLiPSe C++ interface is to keep the 
> interaction between C++ and ECLiPSe simple -- so for example, C++ should 
> just call some simple top-level query, and allow ECLiPSe to do the rest.
> Having said this, you can build arbitrarily complex ECLiPSe structures 
> using the C++ interface, and so you can build any expressions you like. 
> It is not recommended because it is cumbersome, and it is easy to make 
> mistakes, and such mistakes may be hard to catch. If you really want to 
> build such expressions, the embedding and interfacing manual describes 
> how to build structures using the C++ interface.
> Cheers,
> Kish Shen
>> Thank you in advance
>>
>> 2009-08-22 
>>
>>
>>
>> liu.yu.senior.china 
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
>> trial. Simplify your report design, integration and deployment - and focus on 
>> what you do best, core application coding. Discover what's new with 
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ECLiPSe-CLP-Users mailing list
>> ECLiPSe-CLP-Users_at_lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users


-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Mon Aug 24 2009 - 19:20:08 CEST

This archive was generated by hypermail 2.3.0 : Thu Feb 22 2024 - 18:13:20 CET