/
Conjure Revisited Towards Automated Constraint Modelling Ozgur Akgun  Alan M Conjure Revisited Towards Automated Constraint Modelling Ozgur Akgun  Alan M

Conjure Revisited Towards Automated Constraint Modelling Ozgur Akgun Alan M - PDF document

tatiana-dople
tatiana-dople . @tatiana-dople
Follow
402 views
Uploaded On 2015-03-10

Conjure Revisited Towards Automated Constraint Modelling Ozgur Akgun Alan M - PPT Presentation

Frisch Brahim Hnich Chris Je64256erson Ian Miguel School of Computer Science University of St Andrews UK Arti64257cial Intelligence Group Dept of Computer Science University of York UK Department of Computer Engineering Izmir University of Econom ID: 43237

Frisch Brahim Hnich

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Conjure Revisited Towards Automated Cons..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

givenitem_count,capacity:intlettingitembedomainint(1..item_count)givenvolume,value:function(total)item�-int(1..)findx:setofitemmaximisingsumielemx.value(i)suchthat(sumielemx.volume(i))capacity Fig.1.Theknapsackproblem,giveninEssence decisionvariablesintomodelsintheEssence0solver-independentmodellinglanguage.ThisworkwasfurtherdevelopedbyFrischandMartinez-Hernandez[12],wholookedindepthattheissuesinvolvedinchannelingecientlybetweenmanydi erentrepresentationsofhigh-levelvariables.ThispaperdescribesanewapproachtotheimplementationofConjure,withamuchgreatercoverageoftheEssencelanguageandfewerlimitationsontherewriterulessuchastherequirementoftheIJCAIprototypeto attenanEssencespeci cationbeforeapplyingtherewriterules.2BackgroundEssenceisalanguageforspecifyingcombinatorial(decisionoroptimisation)problems(foradetaileddescriptionsee[5]).Itismotivatedbyadesiretoallowuserstowritedownproblemswithoutmakingconstraintmodellingdecisions.Tothisend,ithasahighlevelofabstraction,supportingdecisionvariableswhosetypesmatchthecombinatorialobjectsproblemstypicallyaskusto nd,suchas:sets,multisets,functions,relationsandpartitions.Thekeyadvancerepresentedbythelanguageisitssupportforthenestingofthesetypes,allowingdecisionvariablesoftypesetofsets,multisetofsetsoffunctionsetc.Hence,problemssuchastheSocialGolfersProblem[6],whichisnaturallyconceivedofas ndingasetofpartitionsofgolferssubjecttosomeconstraints,canbespeci eddirectlywithouttheneedtomodelthesetsorpartitionsasmatrices.Concomitantwiththedecisiontosupportabstractconstraintspeci cationsistherequirementtotransformthesespeci cationsintoconstraintmodels.To-day'sconstraintsolverstypicallysupportdecisionvariableswithatomictypes,suchasintegerorBoolean,havelimitedsupportformorecomplextypeslikesetsormultisets,andnosupportfornestedcomplextypes.Hence,abstractspeci ca-tionsmustbere nedintoconstraintmodelssuitableforconstraintsolvers.Thisisachievedbymodellingabstractdecisionvariablesasconstrainedcollectionsofvariablesofmoreprimitivetype.TheConjuresystem, rstpresentedinprototypeformin[4],employsasystemofrewriterulestore neEssencespeci cationsintoconstraintmodelsinEssence0[17],alanguagederivedfromEssencemainlybyremovingfacilitiesforabstractionandaddingfacilitiescommontoexistingconstraintsolversandtoolkits.FromEssence0atoolsuchasTailor[17]canbeusedtotranslatethe Representation Therearetwofundamentaldecisionstobemadeinformu-latingaconstraintmodel.The rstisastotheviewpoint(thechoiceofdecisionvariablesandtheirdomains[9]),andthesecondisthechoiceofconstraintsonthosedecisionvariables.TheConjureprototypeinterleavedthesetwodecisionsinaconstraint-wisere nementprocess[4].Bycontrast,theversionofConjuredescribedhereinexploresallpossibleviewpoints rstbeforeconstraintre nement.ThisphasetakesanEssencespeci ca-tionandgeneratesasetofspeci cations,oneperpossiblecombinationofvariablerepresentationdecisions.Ifavariableappearsinmorethanoneconstraint,itispossibleforthatvariabletoberepresentedindi erentwaysindi erentconstraints,incasethemostecientwayofrepresentingacomplexdecisionvariabledi ersamongtheconstraintsitappearsin.Ifavariableisrepresentedinmorethanonewayinaspeci cation,channellingconstraintsbetweenthetwo(ormore)representationsareaddedautomaticallyinPhase5. Auto-Channelling Ifwechoosemorethanonewayofrepresentingacom-binatorialobjectwithinaspeci cation,weautomaticallyaddchannellingconstraints[12]betweendi erentrepresentationsofthesamevariableinthisphasetomaintainconsistency. Addingstructuralconstraints Inthisphaseweaddallnecessarystructuralconstraintsforeverydecisionvariableinthespeci cation.Thestructuralconstraintforarepresentationofadecisionvariablemakessuretheselectedrepresentationactuallyrepresentsavalidcombinatorialobjectwiththein-tendedproperties(e.g.ensuringthattheelementsofasetaredistinct).Weaddtheseconstraintsbeforerewritingbecausetheywillbeaddedregardlessoftherestofthespeci cationandtheyonlydependontherepresentationofacombinatorialobject.4Non-deterministicRewritingWeemployatermrewritingsystemtore neEssencespeci cationsintothetargetlanguageEssence0.Generally,rewriterulescanbethoughtofaspartialfunctions,whichmapfromasubtermtoanequivalentsubterm[14].Givenasetofrewriterulesandaterm,arewritesystemrepeatedlyappliestherulesuntilnofurtherrulescanbeapplied.Thetermisthensaidtobeinnormalform.Inordertoproducealternativemodelswewishtogeneratenotasinglenormal-formterm,butallnormal-formtermsattainablebyapplyingthegivenrulestotheinputterm.Hence,weadjustthede nitionofarewriterule:insteadofafunctionthatmapsfromasubtermtoanequivalentsubterm,wede nearewriteruletobeafunctionthatmapsfromasubtermtoasetofsubterms.Asingleruleisnowsucienttorepresentthewholeruledatabase.Thissingleruleisaone-to-manymappingfromasubtermtothesetofrewritesofthatsubterm.Thisrepresentationisnaturalwhileapplyingtherules,butitisnotanaturalwaytowritethem.Itis,however,trivialtoautomatethecombinationofasetofpartialfunctionsintothesinglefunctionusedbytheimplementation.Forexamplewecancombinerule1,rule2andrule3inallRulesasfollows: asubseteqb;foralli:a.ielembguards:asetof,bsetof Fig.3.Anexamplerewriterule,ruleSetSubsetEq set,mset,function,relation,tuple.Someoftheavailableoperatorsarethefollowing:abs,+,-,*,/,%,=,!=,,&#x]TJ/;ø 9;&#x.962; Tf;&#x 5.2;̄ ;� Td;&#x[000;,,&#x=]TJ;&#x/F8 ; .96;& T; 10;&#x.460; 0 ;&#xTd[0;=,not,/\,\/,&#x=]TJ;&#x/F8 ; .96;& T; 10;&#x.460; 0 ;&#xTd[0;=,&#x=000;,card,elem,union,intersect,subset,subseteq,supset,supseteq,max,min,forall,exists,sum,matrixindexing([]),tupleindexing(�),functionapplication,functioninverseapplication,relationprojection.ItisusefultoviewourrulesasoperatinguponanAbstractSyntaxTree(AST)representationofanEssencespeci cation.IntheAST,everynoderepresentsaterminthespeci cationandisalsolabelledwiththatterm'stype.TherewritingsystemworksbytraversingtheASTandattemptingtoapplytherulesinthedatabaseateverynode.Aruleisallowedtomodifythesubtreerootedatthecurrentnode,and,forcontextualinformation,isallowedtoaccess(butnottomodify)theremainderoftheASTviatheparentofthecurrentnode.Ifarulematchesthecurrentnode,thewholesubtreeisreplacedwiththeequivalentsubtreetherulesuggests.4.1ExampleRulesInthissectionwewillpresentanumberofexamplerulesrelatingtothere- nementofsetvariables.Thesewilldemonstraterulesshowinghowexpressionsinvolvingsetsarerewrittenandre ned.We rstpresentaseriesofrulesthatdemonstratehowexpressionsinvolvingsetscanberewrittenintoexpressionsinvolvingsimpleroperators. a=b;asubseteqb/\bsubseteqaguards:asetof,bsetofruleSetEq:showsarulethatmatcheswithanequalityconstraintbetweentwosets.Itrewritestheequalityintoaconjunctionofmutualsubseteq'sbetweenthetwosets.Theguardsensureitonlyappliestosets. eelems;existsi:s.i=eguards:e,ssetofruleSetElem:showsarulethatmatcheswithanelemconstraintandrewritesitintoanexistentialquanti cationovertheset. foralli:(aunionb).k;foralli:a.k/\foralli:b.kexistsi:(aunionb).k;existsi:a.k\/existsi:b.kforalli:(aintersectb).k;foralli:a(ielemb�=k)foralli:(aintersectb).k;foralli:b(ielema�=k)existsi:(aintersectb).k;existsi:a(ielemb/\k)existsi:(aintersectb).k;existsi:b(ielema/\k)guards:asetof,bsetof foralli:s.k;foralli:r.kkguards:ssetofint,refinement(s)occurrencedeclarations:m=matrixindexedby[dom]ofbooldom=domain(tau(s))kk=(m[i]=true)�=kexistsi:s.k;existsi:r.kkguards:ssetofint,refinement(s)occurrencedeclarations:m=matrixindexedby[dom]ofbooldom=domain(tau(s))kk=(m[i]=true)/\ksumi:s.k;sumi:r.kkguards:ssetofint,refinement(s)occurrencedeclarations:m=matrixindexedby[dom]ofbooldom=domain(tau(s))kk=(m[i]=true)*kruleRefineSetQuan(occurrencerepresentation):showsthe nalpartofruleRefineSetQuan.Theseruleshandlecaseswherethesetistoberepresentedinoccurrencerepresentation,whereaithelementofamatrixistrueifiisintheset.domainisafunctionwhichreturnsthedomainofitsparameter.tauisafunctionwhichreturnsthetypeofelementacontainertypecontains.5MatchingExpressionsnotConstraintsTheprototypeimplementationdiscussedin[4]operatedbymatchingagainstandrewritingcompleteconstraintsafter atteningallexpressionsbyintroduc-ingauxiliaryvariablesandfurtherconstraints.However,suchanapproachhasanumberofdrawbacks.Itmaynotbescalableingeneralaswemaypossiblyhaveahugenumberofconstrainttypesthatlookverysimilarbutslightlydi erent(suchas:xsubseteq(aunionb)andxsupseteq(aunionb)).Further-more,alargenumberofrewriterulesmaybeneeded,oneforeachconstrainttype.Finally,the atteningprocessmayintroducealargenumberofunneces-saryauxiliaryvariablesandchangesthestructureofourconstraintsforwhichwemayhavebetterrewriterulesthatexploitthatstructure.Inthispaper,weovercomethesedrawbacksbyallowingourrulestomatchandrewriteexpressionswithinaconstraintratherthan(necessarily)thewholeconstraint.Thisallowsustoaccomplishthreethings.First,wecanre neagreaterproportionoftheEssencelanguageusingfewerrules.Second,un-liketheprototype,wenolongerneedto attenaspeci cationpriortore ne-mentavoidingintroducingunnecessaryauxiliaryvariables.Finally,wemayhaveoptimisedrewriterulesforspeci cstructuredconstraints.Forinstance,con-sidertheconstraint(aunionb)subseteqc,ifwe attenit,wewouldhavexsubseteqc/\x=aunionbwhichintroducesanauxiliaryvariableandrequiresre ningunnecessarilyasetequalityconstraint.Inourapproach,inad-ditiontothisre nement,wemayrewritethisintoaconjunctionoftwosubseteqconstraints,namelyasubseteqc/\bsubseteqc,byhavingadedicatedrewriterulewhichreasonsaboutthestructureofthisconstrainttype. foralls:A.(((max_s-max_t)@(bubble_s/\bubble_t))=k)�=(kelems)foralls:A.(((max_s-max_t=k)@(bubble_s/\bubble_t)))�=(kelems)foralls:A.(((max_s-max_t=k)�=(kelems))@(bubble_s/\bubble_t))After ndingtherightpositionsforthebubbles,ournextstepsafelyconverts\@"toconjunction\/\"resultinginthefollowingvalidexpression: foralls:A.(((max_s-max_t=k)�=(kelems))/\bubble_s/\bubble_t)Ouroptionallaststepistoresolvethescopeforthebubbleexpressionsinsideauniversallyquanti edexpression.ruleLoopInvariant,de nedbelow,movesallexpressionsinsideauniversallyquanti edexpressionthatdonotfallinthescopeoftheirquanti er.Theruleisde nedasfollows: foralli:s.k;invariants/\foralli:s.variantsdeclarations:ks=splitConjuctionkvariants=filter(hasReferenceToi)ksinvariants=ksnnvariantsGivenaconjunctionofconstraints,thesplitConjuctionfunctionreturnsalistofconstraintsbreakingtheconjunctionsbetweenthemandthefunctionhasReferenceTocheckswhetherthesecondexpressionreferencesthe rstoneornot.Thus,our nalre nementisasfollows: bubble_t/\foralls:A.(((max_s-max_t=k)�=(kelems))/\bubble_s)6CoverageofEssenceandLimitationsTheEssencelanguageasde nedin[4]contains vecoretypeconstructors:set,multi-set,partition,tuple,functionandrelation;andthesimpletypesint,boolanduser-de nedenumeratedandunnamedtypes.Currentlyoursys-temhasrulesforhandlingspeci cationsonallthetypeconstructors,exceptingpartition.Thereare22operatorsonthesetypeconstructorsde nedin[4].Wesupportalmostallofthem.Thecurrentlymissingoperatorsaremostlyrelatedtotype-conversionandwearecon dentthattheywillbeeasytoimplementwithoutchangestoourcurrentsystem.Sincepartitionscanberealisedassetsofsetswithadditionalconstraints,wearecon dentthatwecansupporttheseinthenearfuture.Wedonotimplementenumeratedtypesandunnamedtypesyet.TheinitialfocusoftheimplementationwasattackingthechallengingpartsofEssencelikethenestedtypes,ratherthanprovidinga nishedproduct.Sinceenumeratedtypesandunnamedtypescanbeeasilytransformedintointbyapreprocessingstep,wepostponetheimplementationofthem. not(a);a=falseguards:aboolruleNot:Thisruleremovesnegatedexpressions. defined(f);defn_fguards:ffunction1�-2,isTotal(f)truedeclarations:defn_f=setof1defined(f);defn_f@bubblguards:ffunction1�-2,representation(f)Func2DisPartial(f)truedeclarations:defn_f=setof1m=matrixindexedby[dom(1),dom(2)]ofboolbubbl=foralli:dom(2).((sumj:dom(1).m[j,i])�0)�=ielemdefn_fruleFuncDefined:Re nesthedefinedoperatorappliedtoafunctionvariable.Simplyreturnsthedomainsetofthefunction,ifthefunctionisdeclaredtobetotal,elseitcreatesasetvariableandconstraintsit. range(f);range_fguards:ffunction1�-2,isSurjective(f)truedeclarations:range_f=setof2range(f);range_f@bubblguards:ffunction1�-2,representation(f)Func2DisSurjective(f)6truedeclarations:range_f=setof2m=matrixindexedby[dom(1),dom(2)]ofboolbubbl=foralli:dom(1).((sumj:dom(2).m[i,j])�0)�=ielemrange_fruleFuncRange:Re nestherangeoperatorappliedtoafunctionvariable.ThisruleissimilartoruleFuncDefined. &#xj000;m[i];&#xj000;nguards:mmatrixindexedby[indices]of omp;&#xonen;&#xts00;tupledeclarations:n=tuple0 omp;&#xs]TJ;&#x/F26;&#x 5.9;ݶ ;&#xTf 1;6.5;ĕ ;.80; Td;&#x[000;comps0=8c2components.matrixindexedby[indices]oftypeof(c)ruleMatrixOfTuples:Essencesupportsmatricesoftuples,howeverthetargetlanguagedoesnot.Thisrulerewritesamatrixoftuplesintoatupleofmatrices,preservingthematrixindexingandthetupleindexing. &#xi000;t;ttguards:t omp;&#xonen;&#xts00;tupleiintegerexpressionlength(components) omp;&#xonen;&#xts00;=ideclarations:tt=typeof(components[i])ruleTupleOut:Rewritesanindexedtupleintoaseparatedecisionvariable. a=b;foralli:r.&#xi000;a=&#xi000;bguards:atuple1 omp;&#xonen;&#xts]T;&#xJ/F2; 5.;靶&#x Tf ;u.3;ŧ ;&#x-0.9;ॣ ;&#xTd[0;,btuple2 omp;&#xonen;&#xts]T;&#xJ/F2; 5.;靶&#x Tf ;u.3;ŧ ;&#x-0.9;ॣ ;&#xTd[0;length(components1)=length(components2)declarations:r=int(0..length(components1)-1) incontrastwithconstraintsolverssuchasIlogSolver[8]andGecode[19],whichareimplementedasalibraryinaprogramminglanguagesuchasC++.TherearetwostandardmethodsforimplementingDSLs.The rstistowriteafullparserandtypecheckerforthelanguageandmapthelanguagetoaninternaldatastructurethatcanbeprocessedandexecuted.Asecond,simplermethodisbyextendinganexistingprogramminglanguage.TheDSLlanguageisthencalledanembedded-DSL(EDSL).Wechooseahybridapproach.WeimplementthelanguageasanEDSLtoHaskelltoleverageitspower,yetwestillimplementacompleteparserandatypecheckerthatcanreadconventionalEssencespeci cationsin.Thismaysoundlikeduplicatingsomework,however,wemakeuseoftheEDSLwhilewritingourrewriterules.UsingtheEDSLforrewriterulessavesusagreatdealofe ortwhichwouldotherwisemeanre-implementingfeaturesofthehostlanguage.Somelanguages,likeHaskell,areparticularlysuitedtothistask,andcanbeusedtoimplementconciseEDSLsthatareeasytouse.Haskellisastaticallytypedhigher-orderpurefunctionalprogramminglanguage.Itprovidesamodulesystem,anadvancedtypesystemwithtypeclassesandpolymorphictypes.Itisparticularlypowerfulinmanipulatingdatastructuresusingitspowerfulpatternmatchinginfrastructure.ThesefeaturesmakeitanaturalcandidateforhostingEDSLs.ThereareEDSLsinHaskellformany eldsincludingbutnotlimitedto3Danimations,imagesynthesisandproduction,andgeometricregionanalysis.Thehmatrix-gplkpackage1providesanEDSLforLinearProgramming,aswellasasolver.Rhiger[18]providesfurtherexamplesofEDSLsinHaskell,anddescribesthecommontechniquesusedtodesignthem.BuildingontopofHaskellgivesustheabilitytoleverageHaskell'srichtypesystemandgrowfromexistingtypesandoperations.Asdiscussedin[5],Essenceitselfisspeci edasasequenceofabstractlexemes.Ourchoiceofcon-cretelexemeswasmadetosuitthehostlanguage.ThemappingtotheabstractlexemesoftheEssencelanguagede nitionisstraightforward.8ConclusionThispaperhaspresentedanewversionoftheConjureautomatedmodellingsystem,whichachievesfargreatercoverageoftheEssencelanguagethanpre-viousversions.ThereremainasmallnumberofareasoftheEssencelanguagethatweneedtoextendthesystemtocover,suchaspartitionvariablesandfunc-tionvariablesthatmapfromarbitrarilynestedtypes.Thisformsanimmediatepieceoffuturework.Furtherfutureworkincludesincreasingthequantityandbreadthofourre nementrulesandbeginningtoselectamongthesetofmodelsproduced.AcknowledgementsOzgurAkgunissupportedbyaSICSAprizestudentship.ThisresearchissupportedbyUKEPSRCgrantnoEP/H004092/1. 1http://hackage.haskell.org/package/hmatrix-glpk