Ejemplo n.º 1
0
const McEnvironment* McObject::getEnvironment() const {
    /* Check if the environment is set into the object */
    if(!environment)
        throw(GeneralError("Object " + getObjectName() + " from module " + getModuleName() +
                           " attempted to access the environment but there isn't a reference to it "));
    return environment;
}
Ejemplo n.º 2
0
GenuineGroundSolverPtr GenuineGroundSolver::getInstance(ProgramCtx& ctx, const OrdinaryASPProgram& p, InterpretationConstPtr frozen, bool minCheck)
{
    //DLVHEX_BENCHMARK_REGISTER_AND_SCOPE(sid, "grounding (GenuineGroundS.::getInst)");

    switch (ctx.config.getOption("GenuineSolver")) {
    case 1:
    case 2:          // internal grounder or Gringo + internal solver
    {
        DBGLOG(DBG, "Instantiating genuine solver with internal solver (min-check: " << minCheck << ")");
        GenuineGroundSolverPtr ptr(minCheck ? new InternalGroundDASPSolver(ctx, AnnotatedGroundProgram(ctx, p), frozen) : new InternalGroundASPSolver(ctx, AnnotatedGroundProgram(ctx, p), frozen));
        return ptr;
    }
    break;
    case 3:
    case 4:          // internal grounder or Gringo + clasp
#ifdef HAVE_LIBCLASP
    {
        DBGLOG(DBG, "Instantiating genuine solver with clasp (min-check: " << minCheck << ")");
        // clasp 3 is always disjunctive
        GenuineGroundSolverPtr ptr(new ClaspSolver(ctx, AnnotatedGroundProgram(ctx, p), frozen));
        return ptr;
    }
#else
    throw GeneralError("No support for clasp compiled into this binary");
#endif                   // HAVE_LIBCLASP
    break;
    default:
        assert(false);
        return GenuineGroundSolverPtr();
    }
}
Ejemplo n.º 3
0
DLVHEX_NAMESPACE_BEGIN

SATSolverPtr SATSolver::getInstance(ProgramCtx& ctx, NogoodSet& ns, InterpretationConstPtr frozen)
{

    switch (ctx.config.getOption("GenuineSolver")) {
        case 3: case 4:          // internal grounder or Gringo + clasp
        #ifdef HAVE_LIBCLASP
            {
                DBGLOG(DBG, "Instantiating genuine sat solver with clasp");
                SATSolverPtr ptr = SATSolverPtr(new ClaspSolver(ctx, ns, frozen));
                return ptr;
            }
        #else
            throw GeneralError("No support for clasp compiled into this binary");
        #endif                   // HAVE_LIBCLINGO
            break;
        case 1: case 2:          // internal grounder or Gringo + internal solver
        default:                 // translation solver
        {
            DBGLOG(DBG, "Instantiating genuine sat solver with internal solver");
                                 // this solver does not implement optimizations, thus all variables are always frozen
            SATSolverPtr ptr = SATSolverPtr(new CDNLSolver(ctx, ns));
            return ptr;
        }
        break;
    }
}
Ejemplo n.º 4
0
DLVHEX_NAMESPACE_BEGIN

GenuineGrounderPtr GenuineGrounder::getInstance(ProgramCtx& ctx, const OrdinaryASPProgram& p, InterpretationConstPtr frozen)
{

    switch(ctx.config.getOption("GenuineSolver")) {
    case 1:
    case 3:          // internal grounder + internal solver or clasp
    {
        if (!!frozen) {
            throw GeneralError("Internal grounder does not support frozen atoms");
        }
        DBGLOG(DBG, "Instantiating genuine grounder with internal grounder");
        GenuineGrounderPtr ptr(new InternalGrounder(ctx, p));
        return ptr;
    }
    break;
    case 2:
    case 4:          // Gringo + internal solver or clasp
#ifdef HAVE_LIBGRINGO
    {
        DBGLOG(DBG, "Instantiating genuine grounder with gringo");
#ifndef GRINGO3      // GRINGO4
        GenuineGrounderPtr ptr(new GringoGrounder(ctx, p, frozen));
#else                // GRINGO3
        //		if (!!frozen){
        //			throw GeneralError("Gringo 3 does not support frozen atoms");
        //		}
        GenuineGrounderPtr ptr(new GringoGrounder(ctx, p, frozen));
#endif
        return ptr;
    }
#else
    throw GeneralError("No support for gringo compiled into this binary");
#endif                   // HAVE_LIBGRINGO
    break;
    default:
        assert(false);
        return GenuineGrounderPtr();
    }
}
Ejemplo n.º 5
0
void DetailList::GetMaterials()
{
   Bool success = TRUE;
   fnMats = 0;
           
   Material m;
   AddMaterial( m );

   for( int di = 0; di < fnDetails; di++ )
      success = success && faDetails[di].GetMaterials( this );
   if( !success )
      throw GeneralError( "Unable to continue!" );
}
Ejemplo n.º 6
0
void InputProvider::addFileInput(const std::string& filename)
{
    std::ifstream ifs;
    ifs.open(filename.c_str());

    if (!ifs.is_open()) {
        throw GeneralError("File " + filename + " not found");
    }

    pimpl->stream << ifs.rdbuf();
    ifs.close();
    pimpl->contentNames.push_back(filename);
}
Ejemplo n.º 7
0
bool CSVAnswerSetPrinterCallback::operator()(
AnswerSetPtr as)
{
    DLVHEX_BENCHMARK_REGISTER_AND_SCOPE(sid,"AnswerSetPrinterCallback");

    // uses the Registry to print the interpretation, including
    // possible influence from AuxiliaryPrinter objects (if any are registered)

    Interpretation::Storage::enumerator it, it_end;

    RegistryPtr reg = as->interpretation->getRegistry();
                                 // must be in this scope!
    Interpretation::Storage filteredbits;
    assert( !!filterpm && "filter must always be defined in CSV format" );

    filterpm->updateMask();
    filteredbits =
        as->interpretation->getStorage() & filterpm->mask()->getStorage();
    it = filteredbits.first();
    it_end = filteredbits.end();

    std::ostream& o = std::cout;
    if (!firstas) o << std::endl;
    firstas = false;

    typedef std::pair<IDAddress, IDAddress> OT;
    std::vector<OT> output;
    while( it != it_end ) {
        const OrdinaryAtom& oatom = reg->ogatoms.getByAddress(*it);
        if (oatom.tuple.size() < 3) throw GeneralError("Atoms which define CSV output must have an arity of 2 or greater.");
        output.push_back(OT(oatom.tuple[1].address, *it));
        ++it;
    }
    std::sort(output.begin(), output.end());
    bool first = true;
    BOOST_FOREACH (OT outputElement, output){
        const OrdinaryAtom& oatom = reg->ogatoms.getByAddress(outputElement.second);
        if (!first) o << std::endl;
        first = false;
        for (int i = 2; i < oatom.tuple.size(); ++i) {
            o << (i > 2 ? ";" : "");
            if (oatom.tuple[i].isIntegerTerm()) o << oatom.tuple[i].address;
            else o << reg->terms.getByID(oatom.tuple[i]).getUnquotedString();
        }
    }

    o << std::endl;

    // never abort
    return true;
}
Ejemplo n.º 8
0
int DetailList::FindMaterial( char *name )
{
   // search through our material list for the material with the
   // given name, and if found, return the index, else return 0.
   // (Not really, since if it's not found it is an error.)

   for( int i = 0; i < fnMats; i++ )
      {
      if( !strcmp( name, faMats[i].fName ) )
         return i;
      }
   throw GeneralError( "Undefined material in mesh!" );
   return 0;
}
Ejemplo n.º 9
0
void StateSet::init_from_datafile(std::string filename) {
	// open other file read-only
	H5::H5File otherfile;
	otherfile.openFile(filename, H5F_ACC_RDONLY);
	H5::Group otherroot = otherfile.openGroup("/");
	// check that grid properties match
	int othersx, othersy, otherN;
	double otherdx;
	otherroot.openAttribute("num_states").read(H5::PredType::NATIVE_INT, &otherN);
	otherroot.openAttribute("grid_sizex").read(H5::PredType::NATIVE_INT, &othersx);
	otherroot.openAttribute("grid_sizex").read(H5::PredType::NATIVE_INT, &othersy);
	otherroot.openAttribute("grid_delta").read(H5::PredType::NATIVE_DOUBLE, &otherdx);
	if (static_cast<int>(N) != otherN)
		throw GeneralError("Cannot copy state data from datafile: value for num_states does not match.");
	if (static_cast<int>(datalayout.sizex) != othersx)
		throw GeneralError("Cannot copy state data from datafile: value for grid_sizex does not match.");
	if (static_cast<int>(datalayout.sizey) != othersy)
		throw GeneralError("Cannot copy state data from datafile: value for grid_sizey does not match.");
	if (datalayout.dx != otherdx)
		throw GeneralError("Cannot copy state data from datafile: value for grid_delta does not match.");
	// copy data
	H5::DataSet other_states_data = otherfile.openDataSet("/states");
	other_states_data.read(state_array->get_dataptr(), other_states_data.getArrayType());
}
Ejemplo n.º 10
0
void InputProvider::addURLInput(const std::string& url)
{
    assert(url.find("http://") == 0 && "currently only processing http:// URLs");

    URLBuf ubuf;
    ubuf.open(url);
    std::istream is(&ubuf);

    pimpl->stream << is.rdbuf();

    if (ubuf.responsecode() == 404) {
        throw GeneralError("Requested URL " + url + " was not found");
    }

    pimpl->contentNames.push_back(url);
}
Ejemplo n.º 11
0
void McEnvironment::parseFiles(const std::vector<std::string>& input_files) {
	/* Check if there is a parser on the environment */
	if (!parser)
		throw(GeneralError("Attempt to parse a file without a parser loaded on the environment"));

	/* Parse information */
	for(vector<string>::const_iterator it = input_files.begin() ; it != input_files.end() ; ++it)
		parser->parseFile((*it));
	/* Get parsed objects */
	vector<McObject*> objects = parser->getObjects();
	/* Put the objects on the map */
	for(vector<McObject*>::iterator it = objects.begin() ; it != objects.end() ; ++it) {
		/* Set the environment where this object is passing through */
		(*it)->setEnvironment(this);
		object_map[(*it)->getModuleName()].push_back((*it));
	}
}
Ejemplo n.º 12
0
// Return the inverse transform corresponding to a transform.
Transform inverse_transform_of(Transform trans) {
	switch (trans) {
		case FFT:
			return iFFT;
		case iFFT:
			return FFT;
		case FFTx:
			return iFFTx;
		case iFFTx:
			return FFTx;
		case FFTy:
			return iFFTy;
		case iFFTy:
			return FFTy;
		case DST:
			return iDST;
		case iDST:
			return DST;
		case DSTx:
			return iDSTx;
		case iDSTx:
			return DSTx;
		case DSTy:
			return iDSTy;
		case iDSTy:
			return DSTy;
		case DCT:
			return iDCT;
		case iDCT:
			return DCT;
		case DCTx:
			return iDCTx;
		case iDCTx:
			return DCTx;
		case DCTy:
			return iDCTy;
		case iDCTy:
			return DCTy;
		default:
			throw GeneralError("Switch statement at inverse_transform_of ended up where it never should.");
			return iFFT;
	}
}
Ejemplo n.º 13
0
/* Sample particle (and check cell) */
void ParticleCellSampler::operator() (CellParticle& particle,Random& r) const {
	/* Number of samples */
	size_t nsamples = 0;
	/* Flag if is inside the cell */
	bool inside = false;
	/* First get the position (rejecting point outside the cell) */
	while(!inside) {
		/* Initial position for sampling */
		particle.second.pos() = position;
		/* Apply position distributions */
		for(vector<DistributionBase*>::const_iterator it = pos_distributions.begin() ; it != pos_distributions.end() ; ++it)
			(*(*it))(particle.second,r);
		/* Check if we are inside the cell */
		for(vector<Cell*>::const_iterator it = cells.begin() ; it != cells.end() ; ++it) {
			/* Get cell */
			const Cell* cell = (*it)->findCell(particle.second.pos());
			if(cell) {
				/* Is inside */
				inside = true;
				/* Set the cell */
				particle.first = cell;
				/* Break loop */
				break;
			}
		}
		/* Count sample */
		nsamples++;
		if(nsamples >= max_samples)
			throw(GeneralError("Sampler efficiency too low on sampler " + getUserId() +
					". Please, reconsider the source definition because this is not a fair game"));
	}
	/* Once the position is set, set phase space coordinates of this sampler */
	particle.second.dir() = direction;
	particle.second.erg() = energy;
	particle.second.wgt() = weight;
	/* Apply distributions (if any) */
	for(vector<DistributionBase*>::const_iterator it = distributions.begin() ; it != distributions.end() ; ++it)
		(*(*it))(particle.second,r);
}
Ejemplo n.º 14
0
void DetailList::AddMaterial( Material &m )
{
   char s[100];

   // handle too many materials:

	if( fnMats == MAX_MATS )
      throw GeneralError( "Too many materials!" );

   // handle duplicate materials:

   for( int i = 0; i < fnMats; i++ )
      if( !strcmp( m.fName, faMats[i].fName ) )
         {
         if( !(faMats[i] == m) )
            {
            sprintf( s, "Material '%s' conflicts with prior material '%s'",
               m.fName, faMats[i].fName );
            throw GeneralError( s );
            }

         // identical duplicate found
         // return without adding duplicate:
         return;
         }

   // if textured, get the actual texture bitmap and add to sheets:
   if( m.fTextured )
      {
      strcpy( m.fTextureFile, m.fRawTextureFile );
      GFXBitmap * pBmp = GFXBitmap::load( m.fRawTextureFile );
      if( pBmp )
         {
         // if texture is translucent, pack the alpha info into it:
         if( m.fTextureHasAlpha )
            {
            GFXBitmap *pAlpha = GFXBitmap::load( m.fAlphaFile );
            if( !pAlpha )
               {
               delete pBmp;
               sprintf( s, "Alpha file missing: '%s'", m.fAlphaFile );
               throw GeneralError( s );
               }
            Alphatize( pBmp, pAlpha );
            delete pAlpha;

            // save alphatized bitmap with .pab extension:
            if( strchr( m.fTextureFile, '.' ) )
               strcpy( strchr( m.fTextureFile, '.' ), ".pab" );
            else
               strcat( m.fTextureFile, ".pab" );
            pBmp->write( m.fTextureFile );
            }
         m.fTransparent = IsTransparent( pBmp );
         delete pBmp;
         }
      else
         {
         sprintf( s, "Texture file missing: '%s'", m.fRawTextureFile );
         throw GeneralError( s );
         }
      }

   // See if TSMaterial is identical to another:
   m.MakeTSMaterial( &faTSMats[fnTSMats] );
   for( int tm = 0; tm < fnTSMats; tm++ )
      if( !memcmp( &m, &faTSMats[tm], sizeof( TSMaterial ) ) )
         {
         // if same as a previous TSMaterial, don't duplicate
         m.fTSMaterialIndex = tm;
         break;
         }

   // allow no duplicates in TSMaterials:
   if( m.fTSMaterialIndex == -1 )
      m.fTSMaterialIndex = fnTSMats++;

   // add all materials here which are unique (if only by name) in 3dStudio:
   faMats[fnMats++] = m;

   // display material attributes:
   //m.Dump();
}
Ejemplo n.º 15
0
void ExtSourceProperties::interpretProperties(RegistryPtr reg, const ExternalAtom& atom, const std::vector<std::vector<std::string> >& props)
{

    DBGLOG(DBG, "Interpreting external source properties");
    typedef std::vector<std::string> Prop;
    BOOST_FOREACH (Prop p, props) {
        // parameter interpretation
        ID param1 = ID_FAIL;
        ID param2 = ID_FAIL;
        if (p.size() > 1) {
            try
            {
                param1 = ID::termFromInteger(boost::lexical_cast<int>(p[1]));
            }
            catch(boost::bad_lexical_cast&) {
                param1 = reg->storeConstantTerm(p[1]);
            }
        }
        if (p.size() > 2) {
            try
            {
                param2 = ID::termFromInteger(boost::lexical_cast<int>(p[2]));
            }
            catch(boost::bad_lexical_cast&) {
                param2 = reg->storeConstantTerm(p[2]);
            }
        }

        // property interpretation
        std::string name = p[0];
        if (name == "functional") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"functional\" expects no parameters");
            DBGLOG(DBG, "External Atom is functional");
            functional = true;
        }
        else if (name == "monotonic") {
            if (param2 != ID_FAIL) throw GeneralError("Property \"monotonic\" expects less than two parameters");
            if (param1 == ID_FAIL) {
                DBGLOG(DBG, "External Atom is monotonic in all input parameters");
                for (uint32_t i = 0; i < atom.inputs.size(); ++i) {
                    monotonicInputPredicates.insert(i);
                }
            }
            else {
                bool found = false;
                for (uint32_t i = 0; i < atom.inputs.size(); ++i) {
                    if (atom.inputs[i] == param1) {
                        DBGLOG(DBG, "External Atom is monotonic in parameter " << i);
                        monotonicInputPredicates.insert(i);
                        found = true;
                        break;
                    }
                }
                if (!found) throw SyntaxError("Property refers to invalid input parameter");
            }
        }
        else if (name == "antimonotonic") {
            if (param2 != ID_FAIL) throw GeneralError("Property \"antimonotonic\" expects less than two parameters");
            if (param1 == ID_FAIL) {
                DBGLOG(DBG, "External Atom is antimonotonic in all input parameters");
                for (uint32_t i = 0; i < atom.inputs.size(); ++i) {
                    antimonotonicInputPredicates.insert(i);
                }
            }
            else {
                bool found = false;
                for (uint32_t i = 0; i < atom.inputs.size(); ++i) {
                    if (atom.inputs[i] == param1) {
                        DBGLOG(DBG, "External Atom is antimonotonic in parameter " << i);
                        antimonotonicInputPredicates.insert(i);
                        found = true;
                        break;
                    }
                }
                if (!found) throw SyntaxError("Property refers to invalid input parameter");
            }
        }
        else if (name == "atomlevellinear" || name == "fullylinear") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"atomlevellinear\" expects no parameters");
            DBGLOG(DBG, "External Atom is linear on atom level");
            atomlevellinear = true;
        }
        else if (name == "tuplelevellinear") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"tuplelevellinear\" expects no parameters");
            DBGLOG(DBG, "External Atom is linear on tuple level");
            tuplelevellinear = true;
        }
        else if (name == "usesenvironment") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"usesenvironment\" expects no parameters");
            DBGLOG(DBG, "External Atom uses environment");
            usesEnvironment = true;
        }
        else if (name == "finitedomain") {
            if (param2 != ID_FAIL) throw GeneralError("Property \"finitedomain\" expects less than two parameters");
            if (param1 == ID_FAIL) {
                DBGLOG(DBG, "External Atom has a finite domain in all output positions");
                for (uint32_t i = 0; i < atom.tuple.size(); ++i) {
                    finiteOutputDomain.insert(i);
                }
            }
            else {
                bool found = false;
                if (!param1.isIntegerTerm()) throw GeneralError("The parameter of property \"finitedomain\" must be an integer");
                finiteOutputDomain.insert(param1.address);
            }
        }
        else if (name == "relativefinitedomain") {
            if (param1 == ID_FAIL || param2 == ID_FAIL) throw GeneralError("Property \"relativefinitedomain\" expects two parameters");
            int wrt;
            bool found = false;
            for (uint32_t i = 0; i < atom.inputs.size(); ++i) {
                if (atom.inputs[i] == param2) {
                    wrt = i;
                    found = true;
                    break;
                }
            }
            if (!found) throw SyntaxError("Property refers to invalid input parameter");
            if (!param1.isIntegerTerm()) throw GeneralError("The first parameter of property \"relativefinitedomain\" must be an integer");
            relativeFiniteOutputDomain.insert(std::pair<int, int>(param1.address, wrt));
        }
        else if (name == "finitefiber") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"finitefiber\" expects no parameters");
            DBGLOG(DBG, "External Atom has a finite fiber");
            finiteFiber = true;
        }
        else if (name == "wellorderingstrlen") {
            if (param1 == ID_FAIL || param2 == ID_FAIL) throw GeneralError("Property \"wellordering\" expects two parameters");
            DBGLOG(DBG, "External Atom has a wellordering using strlen");
            wellorderingStrlen.insert(std::pair<int, int>(param1.address, param2.address));
        }
        else if (name == "wellordering") {
            if (param1 == ID_FAIL || param2 == ID_FAIL) throw GeneralError("Property \"wellordering\" expects two parameters");
            DBGLOG(DBG, "External Atom has a wellordering using natural");
            wellorderingNatural.insert(std::pair<int, int>(param1.address, param2.address));
        }
        else if (name == "supportsets") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"supportsets\" expects no parameters");
            DBGLOG(DBG, "External Atom provides support sets");
            supportSets = true;
        }
        else if (name == "completepositivesupportsets") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"completepositivesupportsets\" expects no parameters");
            DBGLOG(DBG, "External Atom provides complete positive support sets");
            supportSets = true;
            completePositiveSupportSets = true;
        }
        else if (name == "completenegativesupportsets") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"completepositivesupportsets\" expects no parameters");
            DBGLOG(DBG, "External Atom provides complete negative support sets");
            supportSets = true;
            completeNegativeSupportSets = true;
        }
        else if (name == "variableoutputarity") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"variableoutputarity\" expects no parameters");
            DBGLOG(DBG, "External Atom has a variable output arity");
            variableOutputArity = true;
        }
        else if (name == "caresaboutassigned") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"caresaboutassigned\" expects no parameters");
            DBGLOG(DBG, "External Atom cares about assigned atoms");
            caresAboutAssigned = true;
        }
        else if (name == "caresaboutchanged") {
            if (param1 != ID_FAIL || param2 != ID_FAIL) throw GeneralError("Property \"caresaboutchanged\" expects no parameters");
            DBGLOG(DBG, "External Atom has a variable output arity");
            caresAboutChanged = true;
        }
        else {
            throw SyntaxError("Property \"" + name + "\" unrecognized");
        }
    }