xasppkg.c

00001 /* File:      xasppkg.c
00002 ** Author(s): Luis Castro
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: xasppkg.c,v 1.1 2003/02/21 16:57:22 lfcastro Exp $
00023 ** 
00024 */
00025 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include "smodels.h"
00029 #ifndef SMODELS_H
00030 #error "You need the .h and .o files from SModels in your directory"
00031 #endif
00032 #include "api.h"
00033 #include "atomrule.h"
00034 
00035 Smodels *smodels;
00036 Api *api;
00037 Atom **atoms;
00038 int curatom,totatoms; /* current atom, used during creation */
00039 
00040 extern "C" void init(void)
00041 {
00042   smodels = new Smodels;
00043 
00044   api = new Api(&(smodels->program));
00045 }
00046 
00047 extern "C" void numberAtoms(int nAtoms)
00048 {
00049   int i;
00050 
00051   atoms = (Atom **) malloc(sizeof(Atom*)*nAtoms);
00052   for (i=0; i<nAtoms; i++) 
00053     atoms[i] = api->new_atom();
00054 
00055   curatom = 0;
00056   totatoms=nAtoms;
00057 }
00058 
00059 extern "C" void atomName(char *name)
00060 { 
00061   api->set_name(atoms[curatom],name);
00062   curatom++;
00063 }
00064 
00065 extern "C" void beginBasicRule(void)
00066 {
00067   api->begin_rule(BASICRULE);
00068 }
00069 
00070 extern "C" void beginChoiceRule(void)
00071 {
00072   api->begin_rule(CHOICERULE);
00073 }
00074 
00075 extern "C" void beginConstraintRule(void)
00076 {
00077   api->begin_rule(CONSTRAINTRULE);
00078 }
00079 
00080 extern "C" void beginWeightRule(void)
00081 {
00082   api->begin_rule(WEIGHTRULE);
00083 }
00084 
00085 extern "C" void addHead(int atomNum)
00086 {
00087   api->add_head(atoms[atomNum-1]);
00088 }
00089 
00090 extern "C" void addWPosBody(int atomNum,Weight weight)
00091 {
00092   api->add_body(atoms[atomNum-1],true,weight);
00093 }
00094 
00095 extern "C" void addPosBody(int atomNum)
00096 {
00097   api->add_body(atoms[atomNum-1],true);
00098 }
00099 
00100 extern "C" void addWNegBody(int atomNum,Weight weight)
00101 {
00102   api->add_body(atoms[atomNum-1],false,weight);
00103 }
00104 
00105 extern "C" void addNegBody(int atomNum)
00106 {
00107   api->add_body(atoms[atomNum-1],false);
00108 }
00109 
00110 extern "C" void endRule(void)
00111 {
00112   api->end_rule();
00113 }
00114 
00115 extern "C" void commitRules(void)
00116 {
00117   api->done();
00118   smodels->init();
00119 }
00120 
00121 extern "C" void printProgram(void)
00122 {
00123   smodels->program.print();
00124 }
00125 
00126 extern "C" int existsModel(void)
00127 {
00128   return smodels->model();
00129 }
00130 
00131 extern "C" void printAnswer(void)
00132 {
00133   smodels->printAnswer();
00134 }
00135 
00136 extern "C" void close(void)
00137 {
00138   delete(api);
00139   delete(smodels);
00140   free(atoms);
00141 }
00142 
00143 extern "C" int checkAtom(int atom)
00144 {
00145   return atoms[atom-1]->Bpos;
00146 }
00147 
00148 extern "C" void setPosCompute(int atom)
00149 {
00150   api->set_compute(atoms[atom-1],true);
00151 }
00152 
00153 extern "C" void setNegCompute(int atom)
00154 {
00155   api->set_compute(atoms[atom-1],false);
00156 }
00157 
00158 extern "C" void resetPosCompute(int atom)
00159 {
00160   api->reset_compute(atoms[atom-1],true);
00161 }
00162 
00163 extern "C" void resetNegCompute(int atom)
00164 {
00165   api->reset_compute(atoms[atom-1],false);
00166 }
00167 
00168 extern "C" void remember(void)
00169 {
00170   api->remember();
00171 }
00172 
00173 extern "C" void forget(void)
00174 {
00175   api->forget();
00176 }
00177 
00178 extern "C" void setBody(long val)
00179 {
00180   api->set_atleast_body(val);
00181 }
00182 
00183 extern "C" void setWeight(long val)
00184 {
00185   api->set_atleast_weight(val);
00186 }
00187 
00188 extern "C" void setHead(long val)
00189 {
00190   api->set_atleast_head(val);
00191 }
00192 
00193 extern "C" void wellfounded(void)
00194 {
00195   smodels->wellfounded();
00196 }
00197 
00198 extern "C" int testPos(int atom)
00199 {
00200   return smodels->testPos(atoms[atom-1]);
00201 }
00202 
00203 extern "C" int testNeg(int atom)
00204 {
00205   return smodels->testNeg(atoms[atom-1]);
00206 }

Generated on Wed Jul 26 13:30:46 2006 for XSB by  doxygen 1.4.5