|
From: Benjamin K. <kau...@cs...> - 2015-04-09 08:30:45
|
Hi,
you can also achieve this using the configuration options instead of
an external atom. In particular, setting
prg.conf.solve.opt_mode = "ignore"
disables all optimization statements, while
prg.conf.solve.opt_mode = "opt"
(re-)enables them.
For clingo-4.4, there is one catch though: optimize statements that
are initially ignored cannot be enabled later. This will be changed
in the next release.
To make all this more concrete, here is your example using the
configuration options:
#program base.
node(1).
in(X) :- node(X), not out(X).
out(X) :- node(X), not in(X).
#show in/1.
#show out/1.
% Can be moved to base in upcoming clingo-4.5
#program clingo44hack.
#minimize{ 1@B : in(B) }.
#script (python)
from gringo import Fun, SolveResult, Model
def main(prg):
# add in upcoming clingo-4.5
# prg.conf.solve.opt_mode = "ignore"
prg.ground([("base", [])])
# return an arbitrary answer-set
ret = prg.solve([])
# remove in upcoming clingo-4.5
prg.ground([("clingo44hack", [])])
# enable optimization
prg.conf.solve.opt_mode = "opt"
ret = prg.solve([])
# compute again an arbitrary model
prg.conf.solve.opt_mode = "ignore"
ret = prg.solve([])
# again enable optimization
prg.conf.solve.opt_mode = "opt"
ret = prg.solve([])
#end.
Best regards,
Ben
On 04/08/2015 05:46 PM, Johannes Wallner wrote:
> Dear all,
>
> I would like to use the recent clingo + control python interface for
> iteratively calling ASP.
>
> I'm currently trying to encode a workflow that uses iterative calls
> where some of them have optimization statements, and others do not.
>
> In particular in my simple test program (see also below) I tried to
> encode that a single node can either by in or it can be out. With
> weights, assign it to be in has weight 1, and else 0. The simple
> workflow is now:
> 1.) compute some answer set without optimization (node is in or out)
> 2.) assign an external atom 'mini' to enable optimization (result
> should be the node is out)
> 3.) release external 'mini' to compute again an answer-set without
> minimize
> 4.) assign the external 'mini' again to get again an optimal answer-set.
>
> Up until 3.) everything works as intended. For some reason at step 4 no
> optimal answer-set is returned. I think I have some misunderstanding
> what is happening here (or maybe just a plain bug in my encoding :-)
>
> I've searched through the mail archive and could not find a similar
> problem.
>
> In the program below I get as output (I just added newlines
> to highlight the different solving runs):
>
> ====== output ====
> Solving...
> Answer: 1
> in(1)
> Optimization: 0
>
> Solving...
> Answer: 1
> in(1)
> Optimization: 1
> Answer: 2
> out(1)
> Optimization: 0
>
> Solving...
> Answer: 1
> in(1)
> Optimization: 0
>
> Solving...
> Answer: 1
> in(1)
> Optimization: 0
> OPTIMUM FOUND
>
> ... which is as intended except for the last one. Could you assist me in
> finding the problem? I would expect that the last solving call results
> after some iterations in out(1). I haven't used optimization statements
> that often, maybe there is something wrong with this usage? Maybe there
> is something to be 'reset' after the first optimization run?
>
> best,
> Johannes Wallner
>
> ==== program ====
>
> #program base.
> #external mini.
>
> node(1).
>
> in(X) :- node(X), not out(X).
> out(X) :- node(X), not in(X).
>
> #minimize{ 1@B : in(B), mini }.
>
> #show in/1.
> #show out/1.
>
> #script (python)
> from gringo import Fun, SolveResult, Model
>
> def main(prg):
> prg.ground([("base", [])])
>
> # return an arbitrary answer-set
> ret = prg.solve([])
>
> # assign 'mini' to enable optimization
> prg.assign_external(Fun("mini"),True)
> ret = prg.solve([])
>
> # unassign external 'mini'
> prg.release_external(Fun("mini"))
>
> # compute again an arbitrary model
> ret = prg.solve([])
>
> # assign 'mini' to again enable optimization
> prg.assign_external(Fun("mini"),True)
> ret = prg.solve([])
>
> #end.
>
>
>
> ------------------------------------------------------------------------------
> BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
> Develop your own process in accordance with the BPMN 2 standard
> Learn Process modeling best practices with Bonita BPM through live exercises
> http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
> source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
> _______________________________________________
> Potassco-users mailing list
> Pot...@li...
> https://lists.sourceforge.net/lists/listinfo/potassco-users
>
|