Re: [eclipse-clp-users] Segmentation fault when loading large source file

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Tue, 19 Feb 2013 02:25:46 +0000
On 19/02/2013 01:48, Sergii Dymchenko wrote:
> Thank you, Joachim.
>
> I can assure you that this is not a homework, this is a problem from
> recent http://ch24.org/ test round, that took place last Friday.
>
> BTW, I would like to recommend to participate in this contest to all
> fellow ECLiPSe users - the contests rules allow to use any programming
> language or system, and most of the problems have 10 input of
> gradually increasing size, so constraint programming can be used to
> quickly solve some of not so large inputs without inventing
> specialized algorithm. The contest's electronic round scheduled to
> this Saturday, but every team must consist of exactly three members
> and the contest time is inconvenient for the USA.

Too bad, I'll be travelling on Saturday.


> As for your program, group_same_key_values looks a bit intimidating to
> me. I don't think I could had come up with something like this during
> the contest.

I just copied it from the ECLiPSe compiler sources ;)

But here is a simpler way, without sorting and grouping:

     ...
     % create the constraints
     ( for(I,1,NVars), foreach(CI,Consts), param(P,Lines) do
	findall(Line, (member(Line,Lines),Line=[I,_,_]), LinesI),
	( foreach([_I,J,C],LinesI), foreach(Term,Terms), param(P) do
	    Term = C*P[J]
	),
         % state the constraint!
         P[I] $= CI + sum(Terms)
     ),
     ...

[but careful with findall - you can't use it to collect results
containing variables, because it will return copies of them]


-- Joachim
Received on Tue Feb 19 2013 - 02:26:00 CET

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST