// This example uses the ClaspFacade to compute // the stable models of the program // a :- not b. // b :- not a. // // It is similar to example2() but uses the facade's asynchronous // interface in order to get the models one by one. void example3() { // See example2() Clasp::ClaspConfig config; config.solve.numModels = 0; // The "interface" to the clasp library. Clasp::ClaspFacade libclasp; // See example2() Clasp::Asp::LogicProgram& asp = libclasp.startAsp(config); asp.setAtomName(1, "a"); asp.setAtomName(2, "b"); asp.startRule(Clasp::Asp::BASICRULE).addHead(1).addToBody(2, false).endRule(); asp.startRule(Clasp::Asp::BASICRULE).addHead(2).addToBody(1, false).endRule(); // We are done with problem setup. // Prepare the problem for solving. libclasp.prepare(); // Start the asynchronous solving process. Clasp::ClaspFacade::AsyncResult it = libclasp.startSolveAsync(); // Get models one by one until iterator is exhausted. while (!it.end()) { printModel(libclasp.ctx.symbolTable(), it.model()); // Advance iterator to next model. it.next(); } std::cout << "No more models!" << std::endl; }
void CoreSMTSolver::printModel( ) { // Print Boolean model printModel( config.getRegularOut( ) ); // Print Theory model egraph.printModel( config.getRegularOut( ) ); }
void DepthCalibration::onInit() { DiagnosticNodelet::onInit(); if (pnh_->hasParam("coefficients2")) { jsk_topic_tools::readVectorParameter( *pnh_, "coefficients2", coefficients2_); } else { coefficients2_.assign(5, 0); } if (pnh_->hasParam("coefficients1")) { jsk_topic_tools::readVectorParameter( *pnh_, "coefficients1", coefficients1_); } else { coefficients1_.assign(5, 0); coefficients1_[4] = 1.0; } if (pnh_->hasParam("coefficients0")) { jsk_topic_tools::readVectorParameter( *pnh_, "coefficients0", coefficients0_); } else { coefficients0_.assign(5, 0); } pnh_->param("use_abs", use_abs_, false); pnh_->param("uv_scale", uv_scale_, 1.0); printModel(); set_calibration_parameter_srv_ = pnh_->advertiseService( "set_calibration_parameter", &DepthCalibration::setCalibrationParameter, this); pub_ = advertise<sensor_msgs::Image>(*pnh_, "output", 1); }
bool onModel(const Clasp::Solver& s, const Clasp::Model& m) { printModel(s.symbolTable(), m); // exclude this model Clasp::LitVec clause; for (uint32 i = 1; i <= s.decisionLevel(); ++i) { clause.push_back( ~s.decision(i) ); } return m.ctx->commitClause(clause); }
bool DepthCalibration::setCalibrationParameter( SetDepthCalibrationParameter::Request& req, SetDepthCalibrationParameter::Response& res) { boost::mutex::scoped_lock lock(mutex_); coefficients2_ = req.parameter.coefficients2; coefficients1_ = req.parameter.coefficients1; coefficients0_ = req.parameter.coefficients0; use_abs_ = req.parameter.use_abs; printModel(); return true; }
int main(void) { double code; printf("\n\nИзходно съобщение: %s",MESSAGE); getStatistics(MESSAGE); buildModel(MESSAGE); #ifdef SHOW_MORE printModel(); printf("\nНатиснете <<ENTER>>"); getchar(); #endif code = arithmeticEncode(MESSAGE); printf("\nКодът на съобщението е: %1.8f",code); printf("\nДекодиране: "); arithmeticDecode(code,strlen(MESSAGE)); return 0; }
int TestCFSM::runScenario(const int num) { int result = -1; QString scenarioFilename = QString("scenario-%1.txt").arg(num, 2, 10, QChar('0')); QFile inputFile(scenarioFilename); if(inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); processActions(in); result = processResults(in); if(result != 0) { // Test failed! QTextStream console(stdout); console << "--" << endl << "Test failed: " << scenarioFilename << endl; if(result == 1) { console << "Model internal state does not match " << "desired state. Model data:" << endl; printModel(); } console << "--" << endl << endl; } } else { QTextStream console(stdout); console << "ERROR: could not read file: " << scenarioFilename << endl; // Don't try to recover. QApplication::exit(1); } inputFile.close(); return (result); }
void boosted_learning_main(int argc, char *argv[]) { // instantiate parameter object, read all options Parameters::loadParameters(argc, argv); // get task const std::string task = Parameters::getParameter<std::string>("task"); const int verboseLevel = Parameters::getParameter<int>("verbose"); setup_logging(verboseLevel); std::cout << "Task: " << task << std::endl; if (task == "train") { train(verboseLevel); } else if (task == "test") { test(verboseLevel); } else if (task == "bootstrapTrain") { bootstrapTrain(verboseLevel); } else if (task == "printModel") { printModel(); } else { throw std::invalid_argument("unknown task given"); } printf("End of game. Have a nice day !\n"); return; }
void interactive() { char *sbmlFilename; char *select; int quit; SBMLDocument_t *d = NULL; Model_t *m = NULL; odeModel_t *om = NULL; cvodeData_t * data = NULL; integratorInstance_t *ii = NULL; cvodeSettings_t *set = NULL; printf("\n\nWelcome to the simple SBML ODE solver.\n"); printf("You have entered the interactive mode.\n"); printf("All other commandline options have been ignored.\n"); printf("Have fun!\n\n"); initializeOptions(); /* reset steady state */ Opt.SteadyState = 0; /* activate printing of results to XMGrace */ Opt.Xmgrace = 1; /* activate printing integrator messages */ Opt.PrintMessage = 1; /* deactivate on the fly printing of results */ Opt.PrintOnTheFly = 0; sbmlFilename = concat(Opt.ModelPath, Opt.ModelFile); if ( (d = parseModelWithArguments(sbmlFilename)) == 0 ) { Warn(stderr, "%s:%d interactive(): Can't parse Model >%s<", __FILE__, __LINE__, sbmlFilename); d = loadFile(); } /* load models and default settings */ m = SBMLDocument_getModel(d); om = ODEModel_create(m); set = CvodeSettings_create(); SolverError_dumpAndClearErrors(); quit = 0; data = NULL; while ( quit == 0 ) { printf("\n"); printf("Press (h) for instructions or (q) to quit.\n"); printf("> "); select = get_line( stdin ); select = util_trim(select); printf("\n"); if( strcmp(select,"l") == 0 ) { /* free all existing structures */ if ( om != NULL ) ODEModel_free(data->model); if ( d != NULL ) SBMLDocument_free(d); if ( ii != NULL ) IntegratorInstance_free(ii); /* load a new file */ d = loadFile(); /* load new models */ m = SBMLDocument_getModel(d); om = ODEModel_create(m); SolverError_dumpAndClearErrors(); } if(strcmp(select,"h")==0) printMenu(); if(strcmp(select,"s")==0) printModel(m, stdout); if(strcmp(select,"c")==0) printSpecies(m, stdout); if(strcmp(select,"r")==0) printReactions(m, stdout); if(strcmp(select,"o")==0) printODEs(om, stdout); /* integrate interface functions, asks for time and printsteps */ if(strcmp(select,"i")==0){ ii = callIntegrator(om, set); SolverError_dumpAndClearErrors(); } if(strcmp(select,"x")==0){ if ( Opt.Xmgrace == 1 ) { Opt.Xmgrace = 0; printf(" Printing results to stdout\n"); } else if ( Opt.Xmgrace == 0 ) { Opt.Xmgrace = 1; printf(" Printing results to XMGrace\n"); } } if(strcmp(select,"st")==0) printConcentrationTimeCourse(ii->data, stdout); if(strcmp(select,"jt")==0) printJacobianTimeCourse(ii->data, stdout); if(strcmp(select,"ot")==0) printOdeTimeCourse(ii->data, stdout); if(strcmp(select,"rt")==0) printReactionTimeCourse(ii->data, m, stdout); if(strcmp(select,"xp")==0) printPhase(ii->data); if(strcmp(select,"set")==0) setValues(m); if(strcmp(select,"ss")==0){ if ( Opt.SteadyState == 1 ) { Opt.SteadyState = 0; printf(" Not checking for steady states during integration.\n"); } else if ( Opt.SteadyState == 0 ) { Opt.SteadyState = 1; printf(" Checking for steady states during integration.\n"); } } if(strcmp(select,"uj")==0){ if ( Opt.Jacobian == 1 ) { Opt.Jacobian = 0; printf(" Using CVODE's internal approximation\n"); printf(" of the jacobian matrix for integration\n"); } else if ( Opt.Jacobian == 0 ) { Opt.Jacobian = 1; printf(" Using automatically generated\n"); printf(" jacobian matrix for integration\n"); } } if(strcmp(select,"gf")==0) setFormat(); if(strcmp(select,"rg")==0) { drawModel(m, sbmlFilename, Opt.GvFormat); SolverError_dumpAndClearErrors(); } if(strcmp(select,"jg")==0){ if ( ii == NULL ) { data = CvodeData_create(om); CvodeData_initialize(data, set, om, 0); drawJacoby(data, sbmlFilename, Opt.GvFormat); SolverError_dumpAndClearErrors(); CvodeData_free(data); } else { drawJacoby(ii->data, sbmlFilename, Opt.GvFormat); SolverError_dumpAndClearErrors(); } } if(strcmp(select,"j")==0) { if ( om->jacob == NULL ) ODEModel_constructJacobian(om); printJacobian(om, stdout); } if(strcmp(select,"q")==0) quit = 1; } if ( ii != NULL ) IntegratorInstance_free(ii); if ( om != NULL ) ODEModel_free(om); SBMLDocument_free(d); SolverError_dumpAndClearErrors(); printf("\n\nGood Bye. Thx for using.\n\n"); }
int main(int argc, char **argv) { int i; FILE *fout; Imod *imod; extern double meshDiameterSize; int ch; if (argc < 2){ usage(); exit(1); } for (i = 1; i < argc ; i++){ if (argv[i][0] == '-'){ switch (argv[i][1]){ case 'o': ObjectOnly = atoi(argv[++i]); break; case 'l': LinesOnly = 1; break; case 'm': puts("mesh"); break; case '?': usage(); exit(1); break; default: exit(1); break; fprintf(stderr, "imod2meta: unknown option %s\n", argv[i]); } } else break; } if (i >= (argc -1)){ usage(); exit(1); } imod = imodRead(argv[i]); if (!imod){ fprintf(stderr, "Imod2meta: Error reading imod model. (%s)\n", argv[i]); exit(3); } i = argc-1; fout = fopen( argv[i] , "w"); if (fout == NULL){ printf("Couldn't open output file %s.\n", argv[i]); exit(10); } printModel(fout, imod); fclose(fout); exit(0); }
// Compute the stable models of the program // a :- not b. // b :- not a. void example1(bool basicSolve) { // LogicProgram provides the interface for // defining logic programs. // It also preprocesses the program and converts it // to the internal solver format. // See logic_program.h for details. Clasp::Asp::LogicProgram lp; Potassco::RuleBuilder rb; // Among other things, SharedContext maintains a Solver object // which hosts the data and functions for CDNL answer set solving. // See shared_context.h for details. Clasp::SharedContext ctx; // startProgram must be called once before we can add atoms/rules lp.startProgram(ctx); // Define the rules of the program. Potassco::Atom_t a = lp.newAtom(); Potassco::Atom_t b = lp.newAtom(); lp.addRule(rb.start().addHead(a).addGoal(Potassco::neg(b))); lp.addRule(rb.start().addHead(b).addGoal(Potassco::neg(a))); // Populate output table. // The output table defines what is printed for a literal // that is part of an answer set. lp.addOutput("a", a); lp.addOutput("b", b); // It is not limited to atoms. For example, the following // statement results in the ouput "~b" whenever b is not // in a stable model. lp.addOutput("~b", Potassco::neg(b)); // And we always want to have "eureka"... lp.addOutput("eureka", Potassco::toSpan<Potassco::Lit_t>()); // Once all rules are defined, call endProgram() to load the (simplified) // program into the context object. lp.endProgram(); // Since we want to compute more than one // answer set, we need an enumerator. // See enumerator.h for details Clasp::ModelEnumerator enumerator; enumerator.init(ctx); // We are done with problem setup. // Prepare for solving. ctx.endInit(); if (basicSolve) { std::cout << "With Clasp::BasicSolve" << std::endl; // BasicSolve implements a basic search for a model. // It handles the various strategies like restarts, deletion, etc. Clasp::BasicSolve solve(*ctx.master()); // Prepare the solver for enumeration. enumerator.start(solve.solver()); while (solve.solve() == Clasp::value_true) { // Make the enumerator aware of the new model and // let it compute a new constraint and/or backtracking level. if (enumerator.commitModel(solve.solver())) { printModel(ctx.output, enumerator.lastModel()); } // Integrate the model into the search and thereby prepare // the solver for the search for the next model. enumerator.update(solve.solver()); } std::cout << "No more models!" << std::endl; } else { std::cout << "With Clasp::SequentialSolve" << std::endl; // SequentialSolve combines a BasicSolve object, // which implements search for a model and handles // various strategies like restarts, deletion, etc., // with an enumerator to provide more complex reasoning, // like enumeration or optimization. Clasp::SequentialSolve solve; solve.setEnumerator(enumerator); // Start the solve algorithm and prepare solver for enumeration. solve.start(ctx); // Extract and print models one by one. while (solve.next()) { printModel(ctx.output, solve.model()); } if (!solve.more()) { std::cout << "No more models!" << std::endl; } } }
bool onModel(const Clasp::Solver& s, const Clasp::Model& m) { printModel(s.symbolTable(), m); return true; }
int main( int argc, char **argv ) { int sock, len, r; int32_t min, max; uint16_t port; Game *game; MatchState state; Action action; struct sockaddr_in addr; struct hostent *hostent; FILE *file, *toServer, *fromServer; char line[ MAX_LINE_LEN ]; if( argc < 4 ) { fprintf( stderr, "usage: player game server port\n" ); exit( EXIT_FAILURE ); } file = fopen( argv[ 1 ], "r" ); if( file == NULL ) { fprintf( stderr, "ERROR: could not open game %s\n", argv[ 1 ] ); exit( EXIT_FAILURE ); } game = readGame( file ); if( game == NULL ) { fprintf( stderr, "ERROR: could not read game %s\n", argv[ 1 ] ); exit( EXIT_FAILURE ); } fclose( file ); hostent = gethostbyname( argv[ 2 ] ); if( hostent == NULL ) { fprintf( stderr, "ERROR: could not look up address for %s\n", argv[ 2 ] ); exit( EXIT_FAILURE ); } if( sscanf( argv[ 3 ], "%"SCNu16, &port ) < 1 ) { fprintf( stderr, "ERROR: invalid port %s\n", argv[ 3 ] ); exit( EXIT_FAILURE ); } if( ( sock = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) { fprintf( stderr, "ERROR: could not open socket\n" ); exit( EXIT_FAILURE ); } addr.sin_family = AF_INET; addr.sin_port = htons( port ); memcpy( &addr.sin_addr, hostent->h_addr_list[ 0 ], hostent->h_length ); if( connect( sock, (struct sockaddr *)&addr, sizeof( addr ) ) < 0 ) { fprintf( stderr, "ERROR: could not open connect to %s:%"PRIu16"\n", argv[ 2 ], port ); exit( EXIT_FAILURE ); } toServer = fdopen( sock, "w" ); fromServer = fdopen( sock, "r" ); if( toServer == NULL || fromServer == NULL ) { fprintf( stderr, "ERROR: could not get socket streams\n" ); exit( EXIT_FAILURE ); } if( fprintf( toServer, "VERSION:%"PRIu32".%"PRIu32".%"PRIu32"\n", VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION ) != 14 ) { fprintf( stderr, "ERROR: could not get send version to server\n" ); exit( EXIT_FAILURE ); } fflush( toServer ); initModel(game); while( fgets( line, MAX_LINE_LEN, fromServer ) ) { /* ignore comments */ if( line[ 0 ] == '#' || line[ 0 ] == ';' ) { continue; } len = readMatchState( line, game, &state ); if( len < 0 ) { fprintf( stderr, "ERROR: could not read state %s", line ); exit( EXIT_FAILURE ); } if( stateFinished( &state.state ) ) { /* ignore the game over message */ /* debug */ printf("Showdown message: %s", line); updateModel(game, (uint8_t)1-state.viewingPlayer, &state.state); /* pass oppoent position */ #ifdef DEBUG printModel(game); #endif continue; } if( currentPlayer( game, &state.state ) != state.viewingPlayer ) { /* we're not acting */ continue; } /* add a colon (guaranteed to fit because we read a new-line in fgets) */ line[ len ] = ':'; ++len; if( ( random() % 2 ) && raiseIsValid( game, &state.state, &min, &max ) ) { /* raise */ action.type = raise; action.size = min + random() % ( max - min + 1 ); } else { /* call */ action.type = call; action.size = 0; } if( !isValidAction( game, &state.state, 0, &action ) ) { fprintf( stderr, "ERROR: chose an invalid action\n" ); exit( EXIT_FAILURE ); } r = printAction( game, &action, MAX_LINE_LEN - len - 1, &line[ len ] ); if( r < 0 ) { fprintf( stderr, "ERROR: line too long after printing action\n" ); exit( EXIT_FAILURE ); } len += r; line[ len ] = '\n'; ++len; if( fwrite( line, 1, len, toServer ) != len ) { fprintf( stderr, "ERROR: could not get send response to server\n" ); exit( EXIT_FAILURE ); } fflush( toServer ); } return EXIT_SUCCESS; }
int main( const int argc, const char** argv) { int currentOption; bool parameterASet = false; bool parameterBSet = false; bool parameterCSet = false; SelectionHeuristic heuristicMethod = ADAPTIVE; char* outputFilename = NULL; while (1) { static struct option longOptions[] = { {"gaussian", no_argument, &kType, GAUSSIAN}, {"polynomial", no_argument, &kType, POLYNOMIAL}, {"sigmoid", no_argument, &kType, SIGMOID}, {"linear", no_argument, &kType, LINEAR}, {"cost", required_argument, 0, 'c'}, {"heuristic", required_argument, 0, 'h'}, {"tolerance", required_argument, 0, 't'}, {"epsilon", required_argument, 0, 'e'}, {"output", required_argument, 0, 'o'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'f'} }; int optionIndex = 0; currentOption = getopt_long(argc, (char *const*)argv, "c:h:t:e:o:a:r:d:g:v:f", longOptions, &optionIndex); if (currentOption == -1) { break; } int method = 3; switch (currentOption) { case 0: break; case 'v': printf("MICSVM version: 1.0\n"); return(0); case 'f': printHelp(); return(0); case 'c': sscanf(optarg, "%f", &cost); break; case 'h': sscanf(optarg, "%i", &method); switch (method) { case 0: heuristicMethod = FIRSTORDER; break; case 1: heuristicMethod = SECONDORDER; break; case 2: heuristicMethod = RANDOM; break; case 3: heuristicMethod = ADAPTIVE; break; } break; case 't': sscanf(optarg, "%f", &tolerance); break; case 'e': sscanf(optarg, "%f", &epsilon); break; case 'o': outputFilename = (char*)malloc(strlen(optarg)); strcpy(outputFilename, optarg); break; case 'a': sscanf(optarg, "%f", ¶meterA); parameterASet = true; break; case 'r': sscanf(optarg, "%f", ¶meterB); parameterBSet = true; break; case 'd': sscanf(optarg, "%f", ¶meterC); parameterCSet = true; break; case 'g': sscanf(optarg, "%f", ¶meterA); parameterA = -parameterA; parameterASet = true; break; case '?': break; default: abort(); break; } } if (optind != argc - 1) { printHelp(); return(0); } const char* trainingFilename = argv[optind]; if (outputFilename == NULL) { int inputNameLength = strlen(trainingFilename); outputFilename = (char*)malloc(sizeof(char)*(inputNameLength + 5)); strncpy(outputFilename, trainingFilename, inputNameLength + 4); char* period = strrchr(outputFilename, '.'); if (period == NULL) { period = outputFilename + inputNameLength; } strncpy(period, ".mdl\0", 5); } readSvm(trainingFilename, &nPoints, &nDimension); printf("Input data found: %d points, %d dimension\n", nPoints, nDimension); /* alpha = (DataType*)_mm_malloc(nPoints*sizeof(DataType), ALIGNLENGTH); alpha[0:nPoints] = 0; */ alpha = (DataType*)calloc(nPoints, sizeof(DataType)); if (kType == LINEAR) { printf("Linear kernel\n"); //kp.kernel_type = "linear"; } else if (kType == POLYNOMIAL) { if (!(parameterCSet)) { parameterC = 3.0f; } if (!(parameterASet)) { //parameterA = 1.0/nPoints; parameterA = 1.0/nDimension; } if (!(parameterBSet)) { parameterB = 0.0f; } //printf("Polynomial kernel: a = %f, r = %f, d = %f\n", parameterA, parameterB, parameterC); if ((parameterA <= 0) || (parameterB < 0) || (parameterC < 1.0)) { printf("Invalid parameters\n"); exit(1); } kp.kernel_type = "polynomial"; kp.gamma = parameterA; kp.coef0 = parameterB; kp.degree = (int)parameterC; } else if (kType == GAUSSIAN) { if (!(parameterASet)) { //parameterA = 1.0/nPoints; parameterA = 1.0/nDimension; } else { parameterA = -parameterA; } //printf("Gaussian kernel: gamma = %f\n", parameterA); if (parameterA < 0) { printf("Invalid parameters\n"); exit(1); } kp.kernel_type = "rbf"; kp.gamma = parameterA; } else if (kType == SIGMOID) { if (!(parameterASet)) { //parameterA = 1.0/nPoints; parameterA = 1.0/nDimension; } if (!(parameterBSet)) { parameterB = 0.0f; } //printf("Sigmoid kernel: a = %f, r = %f\n", parameterA, parameterB); if ((parameterA <= 0) || (parameterB < 0)) { printf("Invalid Parameters\n"); exit(1); } kp.kernel_type = "sigmoid"; kp.gamma = parameterA; kp.coef0 = parameterB; } struct timeval start,finish; gettimeofday(&start, 0); performTraining(); gettimeofday(&finish, 0); DataType trainingTime = (DataType)(finish.tv_sec - start.tv_sec) + ((DataType)(finish.tv_usec - start.tv_usec)) * 1e-6; printf("all time : %f seconds\n", trainingTime); printModel(outputFilename); return 0; }