/usr/share/mozart/doc/demo/node17.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Constraint script: Script.oz</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node16.html#code.cutting.main"><< Prev</A></TD><TD><A href="cutting.html">- Up -</A></TD><TD><A href="node18.html#code.cutting.edit">Next >></A></TD></TR></TABLE><DIV class="unnumbered" id="code.cutting.script"><H3><A name="code.cutting.script">Constraint script: <CODE>Script.oz</CODE></A></H3><P class="margin"><A href="Cutting/Script.oz">Source File</A></P><P> </P><BLOCKQUOTE><PRE><SPAN class="keyword">functor</SPAN> <BR> <BR><SPAN class="keyword">import</SPAN> <BR> FD Schedule<BR> <BR> <BR><SPAN class="keyword">export</SPAN> <BR> compile: Compile<BR> <BR> <BR><SPAN class="keyword">prepare</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Expand</SPAN> N I Is}<BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> I<SPAN class="keyword">|</SPAN>{Expand N<SPAN class="keyword">-</SPAN>1 I<SPAN class="keyword">+</SPAN>1 Is} <SPAN class="keyword">else</SPAN> Is <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Get</SPAN> J IN Is}<BR> <SPAN class="keyword">if</SPAN> J<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> I<SPAN class="keyword">#</SPAN>N=IN<SPAN class="keyword">.</SPAN>J <SPAN class="keyword">in</SPAN> {Expand N I {Get J<SPAN class="keyword">-</SPAN>1 IN Is}}<BR> <SPAN class="keyword">else</SPAN> Is<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">IN2Is</SPAN> IN}<BR> {Get {Width IN} IN nil}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Get</SPAN> J IN}<BR> N=IN<SPAN class="keyword">.</SPAN>J<SPAN class="keyword">.</SPAN>2<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> J <SPAN class="keyword">else</SPAN> {Get J<SPAN class="keyword">+</SPAN>1 IN} <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">GetMinSizeIN</SPAN> IN}<BR> {Get 1 IN}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Get</SPAN> J IN}<BR> I<SPAN class="keyword">#</SPAN>N=IN<SPAN class="keyword">.</SPAN>J<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> I <SPAN class="keyword">else</SPAN> {Get J<SPAN class="keyword">-</SPAN>1 IN} <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">GetFirstIN</SPAN> IN}<BR> {Get {Width IN} IN}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Get</SPAN> J IN A}<BR> <SPAN class="keyword">if</SPAN> J<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> {Get J<SPAN class="keyword">-</SPAN>1 IN IN<SPAN class="keyword">.</SPAN>J<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">*</SPAN>J<SPAN class="keyword">*</SPAN>J<SPAN class="keyword">+</SPAN>A} <SPAN class="keyword">else</SPAN> A <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">GetAreaIN</SPAN> IN}<BR> {Get {Width IN} IN 0}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR><SPAN class="keyword">define</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Compile</SPAN> Spec}<BR> <BR> %% <SPAN class="comment">Specification is as follows:<BR></SPAN> %% <SPAN class="comment">Spec.x, Spec.y: size of the target plate<BR></SPAN> %% <SPAN class="comment">Spec.squares.D=N: N squares of size D<BR></SPAN> <BR> %% <SPAN class="comment">Number of all squares<BR></SPAN> N = {Record<SPAN class="keyword">.</SPAN>foldL Spec<SPAN class="keyword">.</SPAN>squares Number<SPAN class="keyword">.</SPAN><SPAN class="string">'+'</SPAN> 0}<BR> %% <SPAN class="comment">Dimension of X and Y<BR></SPAN> DX = Spec<SPAN class="keyword">.</SPAN>x<BR> DY = Spec<SPAN class="keyword">.</SPAN>y<BR> %%<SPAN class="comment"> <BR></SPAN> MaxSize = {List<SPAN class="keyword">.</SPAN>last {Arity Spec<SPAN class="keyword">.</SPAN>squares}}<BR> SizeToArea = {MakeTuple <SPAN class="string">'#'</SPAN> MaxSize}<BR> <BR> {For 1 MaxSize 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> SizeToArea<SPAN class="keyword">.</SPAN>I=I<SPAN class="keyword">*</SPAN>I<BR> <SPAN class="keyword">end</SPAN>}<BR> <BR> %% <SPAN class="comment">Mapping: Sqs -> Size<BR></SPAN> SqsSize = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> <BR> %% <SPAN class="comment">Mapping: Sqs -> Area<BR></SPAN> SqsArea = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> <BR> %% <SPAN class="comment">Initialize area and size<BR></SPAN> {Record<SPAN class="keyword">.</SPAN>foldRInd Spec<SPAN class="keyword">.</SPAN>squares<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> D M I}<BR> {For I I<SPAN class="keyword">+</SPAN>M<SPAN class="keyword">-</SPAN>1 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> J}<BR> SqsSize<SPAN class="keyword">.</SPAN>J=D SqsArea<SPAN class="keyword">.</SPAN>J=D<SPAN class="keyword">*</SPAN>D<BR> <SPAN class="keyword">end</SPAN>}<BR> I<SPAN class="keyword">+</SPAN>M<BR> <SPAN class="keyword">end</SPAN> 1 _}<BR> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> Root}<BR> SqsX0 % <SPAN class="comment">left coordinates<BR></SPAN> SqsX1 % <SPAN class="comment">right coordinates<BR></SPAN> SqsY0 % <SPAN class="comment">upper coordinates<BR></SPAN> SqsY1 % <SPAN class="comment">lower coordinates<BR></SPAN> Cuts % <SPAN class="comment">cut information<BR></SPAN> <BR> <SPAN class="keyword">local</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Do</SPAN> J IN MN SqsXY0 SqsXY1 Cut}<BR> <SPAN class="keyword">if</SPAN> J<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> I<SPAN class="keyword">#</SPAN>N=IN<SPAN class="keyword">.</SPAN>J M=MN<SPAN class="keyword">.</SPAN>J <SPAN class="keyword">in</SPAN> <BR> {FD<SPAN class="keyword">.</SPAN>distribute generic(value:mid) [M]}<BR> {For I I<SPAN class="keyword">+</SPAN>M<SPAN class="keyword">-</SPAN>1 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> SqsXY1<SPAN class="keyword">.</SPAN>I <SPAN class="keyword">=<:</SPAN> Cut<BR> <SPAN class="keyword">end</SPAN>}<BR> {For I<SPAN class="keyword">+</SPAN>M I<SPAN class="keyword">+</SPAN>N<SPAN class="keyword">-</SPAN>1 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> SqsXY0<SPAN class="keyword">.</SPAN>I <SPAN class="keyword">>=:</SPAN> Cut<BR> <SPAN class="keyword">end</SPAN>}<BR> {Do J<SPAN class="keyword">-</SPAN>1 IN MN SqsXY0 SqsXY1 Cut}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Position</SPAN> IN MN SqsXY0 SqsXY1 Cut}<BR> {Do MaxSize IN MN SqsXY0 SqsXY1 Cut}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Do</SPAN> J IN MN ?LIN ?RIN LN}<BR> <SPAN class="keyword">if</SPAN> J<SPAN class="keyword">></SPAN>0 <SPAN class="keyword">then</SPAN> <BR> I<SPAN class="keyword">#</SPAN>N=IN<SPAN class="keyword">.</SPAN>J M=MN<SPAN class="keyword">.</SPAN>J<BR> <SPAN class="keyword">in</SPAN> <BR> LIN<SPAN class="keyword">.</SPAN>J = I <SPAN class="keyword">#</SPAN>M<BR> RIN<SPAN class="keyword">.</SPAN>J = (I<SPAN class="keyword">+</SPAN>M)<SPAN class="keyword">#</SPAN>N<SPAN class="keyword">-</SPAN>M<BR> {Do J<SPAN class="keyword">-</SPAN>1 IN MN LIN RIN LN<SPAN class="keyword">+</SPAN>M}<BR> <SPAN class="keyword">else</SPAN> <BR> LN<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">MakeLRIN</SPAN> IN MN ?LIN ?RIN}<BR> LIN = {MakeTuple <SPAN class="string">'#'</SPAN> MaxSize}<BR> RIN = {MakeTuple <SPAN class="string">'#'</SPAN> MaxSize}<BR> {Do {Width IN} IN MN LIN RIN 0} <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">FindXY</SPAN> IN MN I MinSize Area XY0 XY1 DYX SqsXY0 SqsXY1<BR> ?Cut}<BR> AreaL = {FD<SPAN class="keyword">.</SPAN>decl}<BR> <SPAN class="keyword">in</SPAN> <BR> Cut = {FD<SPAN class="keyword">.</SPAN>decl}<BR> %% <SPAN class="comment">cut must be right of first square<BR></SPAN> Cut <SPAN class="keyword">>=:</SPAN> XY0 <SPAN class="keyword">+</SPAN> SqsSize<SPAN class="keyword">.</SPAN>I<BR> %% <SPAN class="comment">cut must be left of at least the smallest square<BR></SPAN> Cut <SPAN class="keyword">+</SPAN> MinSize <SPAN class="keyword">=<:</SPAN> XY1<BR> %% <SPAN class="comment">numbers of squares for left side<BR></SPAN> %% <SPAN class="comment">they occupy AreaL<BR></SPAN> {FD<SPAN class="keyword">.</SPAN>sumC SizeToArea MN <SPAN class="string">'=:'</SPAN> AreaL}<BR> %% <SPAN class="comment">which must fit the left of the cut<BR></SPAN> AreaL <SPAN class="keyword">=<:</SPAN> (Cut<SPAN class="keyword">-</SPAN>XY0) <SPAN class="keyword">*</SPAN> DYX<BR> %% <SPAN class="comment">not all squares must go to the left<BR></SPAN> AreaL <SPAN class="keyword"><:</SPAN> Area<BR> %% <SPAN class="comment">position the squares<BR></SPAN> {FD<SPAN class="keyword">.</SPAN>distribute mid [Cut]}<BR> {Position IN MN SqsXY0 SqsXY1 Cut}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">FindN</SPAN> N IN X0 X1 Y0 Y1}<BR> I = {GetFirstIN IN}<BR> Area = {GetAreaIN IN}<BR> MinSize = {GetMinSizeIN IN}<BR> MN = {Record<SPAN class="keyword">.</SPAN>map IN <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> _<SPAN class="keyword">#</SPAN>N}<BR> {FD<SPAN class="keyword">.</SPAN>int 0<SPAN class="keyword">#</SPAN>N} <BR> <SPAN class="keyword">end</SPAN>}<BR> <SPAN class="keyword">in</SPAN> <BR> %% <SPAN class="comment">place first square<BR></SPAN> SqsX0<SPAN class="keyword">.</SPAN>I=X0 SqsY0<SPAN class="keyword">.</SPAN>I =Y0<BR> %% <SPAN class="comment">mapping of sizes to number of squares on left side<BR></SPAN> <SPAN class="keyword">choice</SPAN> <BR> Cut={FindXY IN MN I MinSize Area X0 X1 Y1<SPAN class="keyword">-</SPAN>Y0 SqsX0 SqsX1}<BR> LIN RIN<BR> LN={MakeLRIN IN MN ?LIN ?RIN}<BR> <SPAN class="keyword">in</SPAN> <BR> info(cut:Cut dir:y<BR> {Find LN LIN X0 Cut Y0 Y1}<BR> {Find N<SPAN class="keyword">-</SPAN>LN RIN Cut X1 Y0 Y1})<BR> <SPAN class="keyword">[]</SPAN> <BR> Cut={FindXY IN MN I MinSize Area Y0 Y1 X1<SPAN class="keyword">-</SPAN>X0 SqsY0 SqsY1}<BR> LIN RIN<BR> LN={MakeLRIN IN MN ?LIN ?RIN}<BR> <SPAN class="keyword">in</SPAN> <BR> info(cut:Cut dir:x<BR> {Find LN LIN X0 X1 Y0 Cut}<BR> {Find N<SPAN class="keyword">-</SPAN>LN RIN X0 X1 Cut Y1})<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Find</SPAN> N IN X0 X1 Y0 Y1}<BR> <SPAN class="keyword">case</SPAN> N<BR> <SPAN class="keyword">of</SPAN> 0 <SPAN class="keyword">then</SPAN> <SPAN class="keyword">fail</SPAN> nil<BR> <SPAN class="keyword">[]</SPAN> 1 <SPAN class="keyword">then</SPAN> [I]={IN2Is IN} <SPAN class="keyword">in</SPAN> <BR> SqsX0<SPAN class="keyword">.</SPAN>I=X0 SqsY0<SPAN class="keyword">.</SPAN>I=Y0<BR> nil<BR> <SPAN class="keyword">[]</SPAN> 2 <SPAN class="keyword">then</SPAN> <BR> [I1 I2]={IN2Is IN}<BR> S1X0=SqsX0<SPAN class="keyword">.</SPAN>I1 S1X1=SqsX1<SPAN class="keyword">.</SPAN>I1 S1Y0=SqsY0<SPAN class="keyword">.</SPAN>I1 S1Y1=SqsY1<SPAN class="keyword">.</SPAN>I1<BR> S2X0=SqsX0<SPAN class="keyword">.</SPAN>I2 S2Y0=SqsY0<SPAN class="keyword">.</SPAN>I2<BR> <SPAN class="keyword">in</SPAN> <BR> S1X0=X0 S1Y0=Y0 <BR> <SPAN class="keyword">dis</SPAN> S2X0=X0 S2Y0=S1Y1 <SPAN class="keyword">then</SPAN> info(cut:S1Y1 dir:x nil nil)<BR> <SPAN class="keyword">[]</SPAN> S2X0=S1X1 S2Y0=Y0 <SPAN class="keyword">then</SPAN> info(cut:S1X1 dir:y nil nil)<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">[]</SPAN> 3 <SPAN class="keyword">then</SPAN> <BR> [I1 I2 I3]={IN2Is IN}<BR> S1X0=SqsX0<SPAN class="keyword">.</SPAN>I1 S1X1=SqsX1<SPAN class="keyword">.</SPAN>I1 S1Y0=SqsY0<SPAN class="keyword">.</SPAN>I1 S1Y1=SqsY1<SPAN class="keyword">.</SPAN>I1<BR> S2X0=SqsX0<SPAN class="keyword">.</SPAN>I2 S2X1=SqsX1<SPAN class="keyword">.</SPAN>I2 S2Y0=SqsY0<SPAN class="keyword">.</SPAN>I2 S2Y1=SqsY1<SPAN class="keyword">.</SPAN>I2<BR> S3X0=SqsX0<SPAN class="keyword">.</SPAN>I3 S3Y0=SqsY0<SPAN class="keyword">.</SPAN>I3<BR> <SPAN class="keyword">in</SPAN> <BR> S1X0=X0 S1Y0=Y0 <BR> <SPAN class="keyword">dis</SPAN> S2X0=X0 S2Y0=S1Y1 S3X0=X0 S3Y0=S2Y1 <SPAN class="keyword">then</SPAN> <BR> info(cut:S1Y1 dir:x nil info(cut:S2Y1 dir:x nil nil))<BR> <SPAN class="keyword">[]</SPAN> S2X0=X0 S2Y0=S1Y1 S3X0=S1X1 S3Y0=S1Y1 <SPAN class="keyword">then</SPAN> <BR> info(cut:S1Y1 dir:x nil info(cut:S2X1 dir:y nil nil))<BR> <SPAN class="keyword">[]</SPAN> S2X0=S1X1 S2Y0=Y0 S3X0=S2X1 S3Y0=Y0 <SPAN class="keyword">then</SPAN> <BR> info(cut:S1X1 dir:y nil info(cut:S2X1 dir:y nil nil))<BR> <SPAN class="keyword">[]</SPAN> S2X0=S1X1 S2Y0=Y0 S3X0=S2X0 S3Y0=S2Y1 <SPAN class="keyword">then</SPAN> <BR> info(cut:S1X1 dir:y nil info(cut:S2Y1 dir:x nil nil))<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">else</SPAN> <BR> {FindN N IN X0 X1 Y0 Y1}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">FindCuts</SPAN>}<BR> IN={MakeTuple <SPAN class="string">'#'</SPAN> MaxSize}<BR> <SPAN class="keyword">in</SPAN> <BR> {ForThread MaxSize 1 <SPAN class="keyword">~</SPAN>1<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I Size}<BR> N={CondSelect Spec<SPAN class="keyword">.</SPAN>squares Size 0}<BR> <SPAN class="keyword">in</SPAN> <BR> IN<SPAN class="keyword">.</SPAN>Size = I<SPAN class="keyword">#</SPAN>N<BR> I<SPAN class="keyword">+</SPAN>N<BR> <SPAN class="keyword">end</SPAN> 1 _}<BR> {Find N IN 0 DX 0 DY}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Fit</SPAN> SqsXY Cap}<BR> {Schedule<SPAN class="keyword">.</SPAN>cumulative [{Arity SqsXY}] SqsXY SqsSize SqsSize [Cap]}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> SqsX0 = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> SqsX1 = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> SqsY0 = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> SqsY1 = {MakeTuple <SPAN class="string">'#'</SPAN> N}<BR> <BR> Root = root(x:SqsX0 y:SqsY0 d:SqsSize dx:DX dy:DY cuts:Cuts)<BR> <BR> <BR> %% <SPAN class="comment">Set up problem variables<BR></SPAN> {For 1 N 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> Size = SqsSize<SPAN class="keyword">.</SPAN>I<BR> X0 = {FD<SPAN class="keyword">.</SPAN>int 0<SPAN class="keyword">#</SPAN>{Max 0 DX<SPAN class="keyword">-</SPAN>Size}}<BR> Y0 = {FD<SPAN class="keyword">.</SPAN>int 0<SPAN class="keyword">#</SPAN>{Max 0 DY<SPAN class="keyword">-</SPAN>Size}}<BR> X1 = {FD<SPAN class="keyword">.</SPAN>decl}<BR> Y1 = {FD<SPAN class="keyword">.</SPAN>decl}<BR> <SPAN class="keyword">in</SPAN> <BR> X1 <SPAN class="keyword">=:</SPAN> X0 <SPAN class="keyword">+</SPAN> Size Y1 <SPAN class="keyword">=:</SPAN> Y0 <SPAN class="keyword">+</SPAN> Size<BR> SqsX0<SPAN class="keyword">.</SPAN>I = X0 SqsY0<SPAN class="keyword">.</SPAN>I = Y0 <BR> SqsX1<SPAN class="keyword">.</SPAN>I = X1 SqsY1<SPAN class="keyword">.</SPAN>I = Y1 <BR> <SPAN class="keyword">end</SPAN>}<BR> <BR> <BR> %% <SPAN class="comment">The squares must fit the target<BR></SPAN> {FD<SPAN class="keyword">.</SPAN>sum SqsArea <SPAN class="string">'=<:'</SPAN> DX<SPAN class="keyword">*</SPAN>DY}<BR> <BR> <BR> %% <SPAN class="comment">Fix some freedom for first square (wolg)<BR></SPAN> SqsX0<SPAN class="keyword">.</SPAN>1=0 SqsY0<SPAN class="keyword">.</SPAN>1=0<BR> <BR> %% <SPAN class="comment">Remove permutations of equally-sized squares by ordering them<BR></SPAN> {For 1 N<SPAN class="keyword">-</SPAN>1 1 <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> I1=I<SPAN class="keyword">+</SPAN>1<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> SqsSize<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">==</SPAN>SqsSize<SPAN class="keyword">.</SPAN>I1 <SPAN class="keyword">then</SPAN> <BR> %% <SPAN class="comment">This is respected by the no overlap<BR></SPAN> SqsX0<SPAN class="keyword">.</SPAN>I <SPAN class="keyword">=<:</SPAN> SqsX0<SPAN class="keyword">.</SPAN>I1<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN>}<BR> <BR> %% <SPAN class="comment">No Overlaps allowed<BR></SPAN> {FD<SPAN class="keyword">.</SPAN>distinct2 SqsX0 SqsSize SqsY0 SqsSize}<BR> <BR> %% <SPAN class="comment">In any direction (be it x or y) the squares must<BR></SPAN> %% <SPAN class="comment">fit into the height/width of the rectangle<BR></SPAN> {Fit SqsX0 DY} {Fit SqsY0 DX}<BR> <BR> %% <SPAN class="comment">The diffuclt part: find the cuts<BR></SPAN> Cuts = {FindCuts}<BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR><SPAN class="keyword">end</SPAN> <BR></PRE></BLOCKQUOTE><P></P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node16.html#code.cutting.main"><< Prev</A></TD><TD><A href="cutting.html">- Up -</A></TD><TD><A href="node18.html#code.cutting.edit">Next >></A></TD></TR></TABLE><HR><ADDRESS><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|