example2.cpp
Go to the documentation of this file.
00001 // 
00002 // Copyright (c) 2009, 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 
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 // The ClaspFacade is a convenient wrapper for the services of the clasp library.
00033 // See clasp_facade.h for details.
00034 
00035 
00036 // In order to get models from the ClaspFacade, we must provide a suitable
00037 // event handler.
00038 class ModelPrinter : public Clasp::EventHandler {
00039 public:
00040         ModelPrinter() {}
00041         bool onModel(const Clasp::Solver& s, const Clasp::Model& m) {
00042                 printModel(s.symbolTable(), m);
00043                 return true;
00044         }
00045 };
00046 
00047 void example2() {
00048         // Aggregates configuration options.
00049         // Using config, you can control many parts of the search, e.g.
00050         // - the amount and kind of preprocessing
00051         // - the enumerator to use and the number of models to compute
00052         // - the heuristic used for decision making
00053         // - the restart strategy
00054         // - ...
00055         Clasp::ClaspConfig config;
00056         // We want to compute all models but
00057         // otherwise we use the default configuration.
00058         config.enumerate.numModels = 0;
00059         
00060         // The "interface" to the clasp library.
00061         Clasp::ClaspFacade libclasp;
00062 
00063         // LogicProgram provides the interface for defining logic programs.
00064         // The returned object is already setup and ready to use.
00065         // See logic_program.h for details.
00066         Clasp::Asp::LogicProgram& asp = libclasp.startAsp(config);
00067         asp.setAtomName(1, "a");
00068         asp.setAtomName(2, "b");
00069         asp.startRule(Clasp::Asp::BASICRULE).addHead(1).addToBody(2, false).endRule();
00070         asp.startRule(Clasp::Asp::BASICRULE).addHead(2).addToBody(1, false).endRule();
00071         
00072         // We are done with problem setup. 
00073         // Prepare the problem for solving.
00074         libclasp.prepare();
00075 
00076         // Start the actual solving process.
00077         ModelPrinter printer;
00078         libclasp.solve(&printer);
00079         std::cout << "No more models!" << std::endl;
00080 }


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