Esempio n. 1
0
/** dumpPlane **/
void dumpPlane(FILE *outFP, entity_t *ent) {
   assert(ent->magic == ENTITY_T);
   sobj_t *sobj = ent->entDerived;
   assert(sobj->magic == SCENEOBJ_T);
   plane_t *plane = sobj->sobjDerived;
   assert(plane->magic == PLANE_T);

   dumpSceneObj(outFP, ent);

   printTuple(outFP,  "   point:     ", plane->point);
   printTuple(outFP,  "   orient1:   ", plane->orient1);
   printTuple(outFP,  "   orient2:   ", plane->orient2);
   printTuple(outFP,  "   normal:    ", plane->normal);
}
Esempio n. 2
0
void dumpPointLight(FILE *outFP, entity_t *ent) {
    
    assert(ent->magic == ENTITY_T);
    
    pointlight_t *pointlight = ent->entDerived;
    
    dumpEntity(outFP, ent);
    fprintf(outFP, "   color:        %6d   %6d   %6d\n",pointlight->color.r,pointlight->color.g,pointlight->color.b);
    fprintf(outFP, "   brightness: %8.4lf\n",pointlight->brightness);
    printTuple(outFP, "   center:    ",pointlight->center);
}
Esempio n. 3
0
int main (void) {
    int i = 0;
    CLSTList list = lz77Compress("A_ASA_DA_CASA", 5, 3);
    LZ77Tuple_ST* current_tuple_p = NULL;

    for (current_tuple_p = clstLookFirstElement(list);
         current_tuple_p != NULL;
         current_tuple_p = clstLookElement(list, i ++))
        printTuple(*current_tuple_p);

    return 0;
}
Esempio n. 4
0
void PrintToScreen::PrintRelation(const CatalogRelation &relation,
                                  StorageManager *storage_manager,
                                  FILE *out) {
  if (!FLAGS_printing_enabled) {
    return;
  }

  vector<int> column_widths;
  column_widths.reserve(relation.size());

  for (CatalogRelation::const_iterator attr_it = relation.begin();
       attr_it != relation.end();
       ++attr_it) {
    // Printed column needs to be wide enough to print:
    //   1. The attribute name (in the printed "header").
    //   2. Any value of the attribute's Type.
    //   3. If the attribute's Type is nullable, the 4-character string "NULL".
    // We pick the largest of these 3 widths as the column width.
    int column_width = static_cast<int>(attr_it->getDisplayName().length());
    column_width = column_width < attr_it->getType().getPrintWidth()
                   ? attr_it->getType().getPrintWidth()
                   : column_width;
    column_width = attr_it->getType().isNullable() && (column_width < 4)
                   ? 4
                   : column_width;
    column_widths.push_back(column_width);
  }

  printHBar(column_widths, out);

  fputc('|', out);
  vector<int>::const_iterator width_it = column_widths.begin();
  CatalogRelation::const_iterator attr_it = relation.begin();
  for (; width_it != column_widths.end(); ++width_it, ++attr_it) {
    fprintf(out,
            "%-*s|",
            *width_it,
            attr_it->getDisplayName().c_str());
  }
  fputc('\n', out);

  printHBar(column_widths, out);

  std::vector<block_id> blocks = relation.getBlocksSnapshot();
  for (const block_id current_block_id : blocks) {
    BlockReference block = storage_manager->getBlock(current_block_id, relation);
    const TupleStorageSubBlock &tuple_store = block->getTupleStorageSubBlock();

    if (tuple_store.isPacked()) {
      for (tuple_id tid = 0; tid <= tuple_store.getMaxTupleID(); ++tid) {
        printTuple(tuple_store, tid, column_widths, out);
      }
    } else {
      std::unique_ptr<TupleIdSequence> existence_map(tuple_store.getExistenceMap());
      for (tuple_id tid : *existence_map) {
        printTuple(tuple_store, tid, column_widths, out);
      }
    }
  }

  printHBar(column_widths, out);
}
/**
 * @brief Best Model Selector, Execution Schedule Builder, Execute Actions on Environment
 */
void ActionPluginFinalCallback::operator()() {
	DBGLOG(DBG, "\nActionPluginFinalCallback called");

	if (ctxData.nameBestModelSelectorMap.count(
			ctxData.getBestModelSelectorSelected()) == 0)
		throw PluginError("The BestModelSelector chosen doesn't exist");

	ctxData.nameBestModelSelectorMap[ctxData.getBestModelSelectorSelected()]->getBestModel(
			ctxData.iteratorBestModel, ctxData.bestModelsContainer);

	std::stringstream ss;
	(*ctxData.iteratorBestModel)->interpretation->print(ss);
	DBGLOG(DBG, "\nBestModel selected: " << ss.str());

	DBGLOG(DBG, "\nCall the executionModeController");
	std::multimap<int, Tuple> multimapOfExecution;
	executionModeController(multimapOfExecution);

	DBGLOG(DBG, "\nThe MultiMapOfExecution:");
	DBGLOG(DBG, "Precedence\tTuple");
	std::multimap<int, Tuple>::iterator itMMOE;
	for (itMMOE = multimapOfExecution.begin();
			itMMOE != multimapOfExecution.end(); itMMOE++) {
		const Tuple& tempTuple = itMMOE->second;
		std::stringstream ss;
		printTuple(ss, tempTuple, registryPtr);
		DBGLOG(DBG, itMMOE->first << "\t\t" << ss.str());
	}

	if (ctxData.nameExecutionScheduleBuilderMap.count(
			ctxData.getExecutionScheduleBuilderSelected()) == 0)
		throw PluginError("The ExecutionScheduleBuilder chosen doesn't exist");

	DBGLOG(DBG, "\nCall the executionScheduleBuilder");
	std::list < std::set<Tuple> > listOfExecution;
	ctxData.nameExecutionScheduleBuilderMap[ctxData.getExecutionScheduleBuilderSelected()]->rewrite(
			multimapOfExecution, listOfExecution, (*(ctxData.iteratorBestModel))->interpretation);

	DBGLOG(DBG, "\nThe ListOfExecution:");
	std::list<std::set<Tuple> >::iterator itLOE;
	for (itLOE = listOfExecution.begin(); itLOE != listOfExecution.end();
			itLOE++) {
		std::set < Tuple > &tempSet = (*itLOE);
		for (std::set<Tuple>::iterator itLOEs = tempSet.begin();
				itLOEs != tempSet.end(); itLOEs++) {
			const Tuple& tempTuple = (*itLOEs);
			std::stringstream ss;
			printTuple(ss, tempTuple, registryPtr);
			DBGLOG(DBG, ss.str());
		}
	}

	DBGLOG(DBG,
			"\nControl if the order of Set in the List corresponds to their precedence");
	if (checkIfTheListIsCorrect(multimapOfExecution, listOfExecution)) {
		DBGLOG(DBG, "The List is correct");
	} else {
		DBGLOG(DBG, "The List isn't correct");
		throw PluginError(
				"The order of Set in the ListOfExecution doens't correspond to their precedence");
	}

	DBGLOG(DBG, "\nExecute the actions in the right order");

	for (itLOE = listOfExecution.begin(); itLOE != listOfExecution.end();
			itLOE++) {

		std::set < Tuple > &tempSet = (*itLOE);

		for (std::set<Tuple>::iterator itLOEs = tempSet.begin();
				itLOEs != tempSet.end(); itLOEs++) {

			const Tuple& tempTuple = (*itLOEs);

			if (*tempTuple.begin() == ctxData.getIDContinue()) {
				ctxData.continueIteration = true;
				continue;
			} else if (*tempTuple.begin() == ctxData.getIDStop()) {
				ctxData.stopIteration = true;
				continue;
			}

			Tuple tupleForExecute;
			tupleForExecute.insert(tupleForExecute.begin(),
					tempTuple.begin() + 1, tempTuple.end());

			std::stringstream ss;
			printTuple(ss, tempTuple, registryPtr);
			DBGLOG(DBG, "tupleForExecute: " << ss.str());
			ss.str("");
			printTuple(ss, tupleForExecute, registryPtr);
			DBGLOG(DBG, "tempTuple: " << ss.str());

			std::map<std::string, PluginActionBasePtr>::iterator it =
					ctxData.namePluginActionBaseMap.find(
							registryPtr->getTermStringByID(*tempTuple.begin()));

			if (it != ctxData.namePluginActionBaseMap.end())
				it->second->execute(programCtx,
						(*(ctxData.iteratorBestModel))->interpretation,
						tupleForExecute);
			else
				DBGLOG(DBG,
						"For the action '"
								<< registryPtr->getTermStringByID(
										*tempTuple.begin())
								<< "' wasn't found a definition");

		}
	}

	DBGLOG(DBG, "\nCheck Iteration");
	if (ctxData.getIterationType() == DEFAULT && ctxData.continueIteration)
		programCtx.config.setOption("RepeatEvaluation", 1);
	else if (ctxData.getIterationType() != DEFAULT && ctxData.stopIteration)
		programCtx.config.setOption("RepeatEvaluation", 0);
	else if (ctxData.getIterationType() == INFINITE)
		programCtx.config.setOption("RepeatEvaluation", 1);
	else if (ctxData.getIterationType() == FIXED) {
		if (!ctxData.getTimeDuration().is_not_a_date_time()) {
			boost::posix_time::time_duration diff =
					boost::posix_time::second_clock::local_time()
							- ctxData.getStartingTime();
			if (diff > ctxData.getTimeDuration())
				programCtx.config.setOption("RepeatEvaluation", 0);
			else if (ctxData.getNumberIterations() != -1) {
				programCtx.config.setOption("RepeatEvaluation",
						ctxData.getNumberIterations());
				ctxData.decreaseNumberIterations();
			} else
				programCtx.config.setOption("RepeatEvaluation", 1);
		}
	}

	if (programCtx.config.getOption("RepeatEvaluation") > 0) {

		DBGLOG(DBG, "\nIncrease iteration in the UtilitiesPlugin");
		ctxData.increaseIteration(programCtx);

		DBGLOG(DBG, "\nClear data structures");
		ctxData.clearDataStructures();

		ctxData.continueIteration = false;
		ctxData.stopIteration = false;

		DBGLOG(DBG, "\nReset cache");
		programCtx.resetCacheOfPlugins();

	}

}
/**
 * @brief function that fill the multimap (passed as parameter) with Precedence attribute and Action Tuple checking the Action Option attribute
 */
void ActionPluginFinalCallback::executionModeController(
		std::multimap<int, Tuple>& multimapOfExecution) {

	const AnswerSetPtr& bestModel = (*(ctxData.iteratorBestModel));

	// used to have only the Action Atoms
	InterpretationPtr intr = InterpretationPtr(new Interpretation(registryPtr));
	intr->getStorage() |= ctxData.myAuxiliaryPredicateMask.mask()->getStorage();
	intr->getStorage() &= bestModel->interpretation->getStorage();

	Interpretation::TrueBitIterator bit, bit_end;
	for (boost::tie(bit, bit_end) = intr->trueBits(); bit != bit_end; ++bit) {

		const OrdinaryAtom& oatom = registryPtr->ogatoms.getByAddress(*bit);
		const Tuple & tuple = oatom.tuple;

		int precedence, precedence_position = tuple.size() - 3;
		dlvhex::ID id_actionOption = tuple[tuple.size() - 4];

		Tuple action_tuple;

		for (int i = 1; i < tuple.size() - 4; i++)
			action_tuple.push_back(tuple[i]);

		if (tuple[precedence_position].isIntegerTerm()
				&& id_actionOption.isConstantTerm()) {

			precedence = tuple[precedence_position].address;

			DBGLOG(DBG,
					"actionOption: "
							<< registryPtr->getTermStringByID(id_actionOption));
			DBGLOG(DBG, "Precedence: " << precedence);

			if (id_actionOption == ctxData.getIDBrave())
				;
			else if (id_actionOption == ctxData.getIDCautious())
				if (!isPresentInAllAnswerSets(action_tuple)) {
					std::stringstream ss;
					printTuple(ss, action_tuple, registryPtr);
					DBGLOG(DBG,
							"This action atom isn't present in all AnswerSet: "
									<< ss.str());
					continue;
				} else if (id_actionOption == ctxData.getIDPreferredCautious())
					if (!isPresentInAllTheBestModelsAnswerSets(action_tuple)) {
						std::stringstream ss;
						printTuple(ss, action_tuple, registryPtr);
						DBGLOG(DBG,
								"This action atom isn't present in all BestModels AnswerSet: "
										<< ss.str());
						continue;
					} else
						throw PluginError(
								"Error in the selection of brave, cautious or preferred_cautious");

			multimapOfExecution.insert(
					std::pair<int, Tuple>(precedence, action_tuple));

		} else
			throw PluginError(
					"Precedence isn't Integer term or actionOption haven't a valid value");

	}

}