example3.cpp
Go to the documentation of this file.
00001 // 
00002 // Copyright (c) 2014, Benjamin Kaufmann
00003 // 
00004 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/ 
00005 // 
00006 // Clasp is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // Clasp is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with Clasp; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 #if WITH_THREADS
00021 // Add the libclasp directory to the list of 
00022 // include directoies of your build system.
00023 #include <clasp/clasp_facade.h>
00024 #include <clasp/solver.h>
00025 #include "example.h"
00026 
00027 // This example uses the ClaspFacade to compute
00028 // the stable models of the program
00029 //    a :- not b.
00030 //    b :- not a.
00031 //
00032 // It is similar to example2() but uses the facade's asynchronous
00033 // interface in order to get the models one by one.
00034 void example3() {
00035         // See example2()
00036         Clasp::ClaspConfig config;
00037         config.enumerate.numModels = 0;
00038         
00039         // The "interface" to the clasp library.
00040         Clasp::ClaspFacade libclasp;
00041 
00042         // See example2()
00043         Clasp::Asp::LogicProgram& asp = libclasp.startAsp(config);
00044         asp.setAtomName(1, "a");
00045         asp.setAtomName(2, "b");
00046         asp.startRule(Clasp::Asp::BASICRULE).addHead(1).addToBody(2, false).endRule();
00047         asp.startRule(Clasp::Asp::BASICRULE).addHead(2).addToBody(1, false).endRule();
00048         
00049         // We are done with problem setup. 
00050         // Prepare the problem for solving.
00051         libclasp.prepare();
00052 
00053         // Start the asynchronous solving process.
00054         Clasp::ClaspFacade::AsyncResult it = libclasp.startSolveAsync();
00055         // Get models one by one until iterator is exhausted.
00056         while (!it.end()) {
00057                 printModel(libclasp.ctx.symbolTable(), it.model());
00058                 // Advance iterator to next model.
00059                 it.next();
00060         }
00061         std::cout << "No more models!" << std::endl;
00062 }
00063 #endif


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:39