XML * DSREP_localxml_new (WFTK_ADAPTOR * ad, va_list args) { char path[256]; struct stat statbuf; char * id = (char *) 0; FILE * file; XML * ret = xml_create ("datasheet"); if (args) id = va_arg (args, char *); if (id) { strcpy (path, xml_attrval (ad->parms, "dir")); strcat (path, id); strcat (path, ".xml"); if (stat (path, &statbuf) == -1) { file = fopen (path, "w"); if (file) { xml_set (ret, "id", id); xml_write (file, ret); fclose (file); } else { xml_set (ad->parms, "error", "Couldn't open file for writing."); } } else { xml_set (ad->parms, "error", "File already exists."); } } return ret; }
Bool load_config (const char *filename) { int rc; XML_ITEM *config = NULL; XML_ITEM *root = NULL; char fullname[FILE_NAME_MAX + 1]; root = xml_create ("root", NULL); ASSERT (filename != NULL); ASSERT (strlen(filename) < FILE_NAME_MAX); default_extension (fullname, filename, "cfg"); rc = xml_load_file (&root, ".", fullname, FALSE); if (rc != XML_NOERROR) { coprintf ("Error while loading \"%s\". Check file presence and consistence", fullname); display_usage (); return FALSE;; } config = xml_first_child (root); ASSERT (config); /* default server is localhost */ main_server = mem_strdup (xml_get_attr (config, "smtp", "127.0.0.1")); main_sender = mem_strdup (xml_get_attr (config, "sender", "admin@crjo")); main_dest = mem_strdup (xml_get_attr (config, "dest", "user@crjo")); xml_free (root); return TRUE; }
int fmll_svm_net_save(const fmll_svm_net * svm_net, const char * fname_prefix) { int ret = 0; const unsigned num = svm_net->num; unsigned u; char node_name[4096]; const fmll_svm ** svm = (const fmll_svm **) svm_net->svm; mxml_node_t * sub_node, * node, * content_node, * main_node = NULL; fmll_try; fmll_throw_if(xml_create(TYPE_SVM_NET, & main_node, & content_node)); fmll_throw_if(xml_set_int(content_node, "num", num)); fmll_throw_null(node = mxmlNewElement(content_node, "SVM")); for(u = 0; u < num; u++) { sprintf(node_name, "svm_%u", u); fmll_throw_null(sub_node = mxmlNewElement(node, node_name)); fmll_throw_if(fmll_svm_save_main(svm[u], sub_node)); } fmll_throw_if(xml_save(fname_prefix, main_node)); fmll_catch; ret = -1; fmll_finally; xml_destroy(main_node); return ret; }
XML * DSREP_localxml_info (WFTK_ADAPTOR * ad, va_list args) { XML * info; info = xml_create ("info"); xml_set (info, "type", "dsrep"); xml_set (info, "name", "localxml"); xml_set (info, "ver", "1.0.0"); xml_set (info, "compiled", __TIME__ " " __DATE__); xml_set (info, "author", "Michael Roberts"); xml_set (info, "contact", "*****@*****.**"); xml_set (info, "extra_functions", "0"); return (info); }
int fmll_som_save(const fmll_som * som, const char * fname_prefix) { int ret = 0; const unsigned num = som->num, map_dim = som->map_dim, dim = som->dim, * N = som->N; const double ** w = (const double **) som->w; char node_name[4096]; unsigned u, v; mxml_node_t * sub_node, * node, * content_node, * main_node = NULL; fmll_try; fmll_throw_if(xml_create(TYPE_SOM, & main_node, & content_node)); fmll_throw_if(xml_set_int(content_node, "map_dim", map_dim)); fmll_throw_if(xml_set_int(content_node, "dim", dim)); fmll_throw_null(node = mxmlNewElement(content_node, "N")); for(u = 0; u < map_dim; u++) { sprintf(node_name, "N_%u", u); fmll_throw_if(xml_set_int(node, node_name, N[u])); } fmll_throw_null(node = mxmlNewElement(content_node, "W")); for(u = 0; u < num; u++) { sprintf(node_name, "w_%u", u); fmll_throw_null(sub_node = mxmlNewElement(node, node_name)); for(v = 0; v < dim; v++) { sprintf(node_name, "%u", v); fmll_throw_if(xml_set_double(sub_node, node_name, w[u][v])); } } fmll_throw_if(xml_save(fname_prefix, main_node)); fmll_catch; ret = -1; fmll_finally; xml_destroy(main_node); return ret; }
XML * TASKINDEX_stdout_info (WFTK_ADAPTOR * ad, va_list args) { XML * info; info = xml_create ("info"); xml_set (info, "type", "taskindex"); xml_set (info, "name", "stdout"); xml_set (info, "ver", "1.0.0"); xml_set (info, "compiled", __TIME__ " " __DATE__); xml_set (info, "author", "Michael Roberts"); xml_set (info, "contact", "*****@*****.**"); xml_set (info, "extra_functions", "0"); return (info); }
XML_ITEM * xml_new ( XML_ITEM *parent, const char *name, const char *value) { XML_ITEM *item; item = xml_create (name, value); if (item && parent) xml_attach_child (parent, item); return item; }
int fmll_pca_save(const fmll_pca * pca, const char * fname_prefix) { int ret = 0; const unsigned dim = pca->dim, num = pca->num; const double ** w = (const double **) pca->w; unsigned u, v; char node_name[4096]; mxml_node_t * sub_node, * node, * main_node = NULL, * content_node; fmll_try; fmll_throw_if(xml_create(TYPE_PCA, & main_node, & content_node)); fmll_throw_if(xml_set_int(content_node, "dim", dim)); fmll_throw_if(xml_set_int(content_node, "num", num)); fmll_throw_null(node = mxmlNewElement(content_node, "W")); for(u = 0; u < num; u++) { sprintf(node_name, "w_%u", u); fmll_throw_null(sub_node = mxmlNewElement(node, node_name)); for(v = 0; v < dim; v++) { sprintf(node_name, "%u", v); fmll_throw_if(xml_set_double(sub_node, node_name, w[u][v])); } } fmll_throw_if(xml_save(fname_prefix, main_node)); fmll_catch; ret = -1; fmll_finally; xml_destroy(main_node); return ret; }
XML * PDREP_localxml_version (WFTK_ADAPTOR * ad, va_list args) { char path[256]; char * id = (char *) 0; FILE * file; XML * index; XML * value; xml_set (ad->parms, "error", ""); if (args) id = va_arg (args, char *); if (!id) { xml_set (ad->parms, "error", "No ID given."); return (XML *) 0; } strcpy (path, xml_attrval (ad->parms, "dir")); strcat (path, id); strcat (path, "__versions.xml"); file = fopen (path, "r"); if (!file) { xml_set (ad->parms, "error", "Procdef master file not found."); return (XML *) 0; } index = xml_read (file); if (!index) { xml_set (ad->parms, "error", "Procdef master file corrupted."); return (XML *) 0; } value = xml_create ("value"); xml_set (value, "value", xml_attrval (index, "ver")); xml_free (index); fclose (file); return value; }
XML * DSREP_localxml_save (WFTK_ADAPTOR * ad, va_list args) { char path[256]; struct stat statbuf; XML * ds = (XML *) 0; FILE * file; FILE * _index; XML * index; int counter; if (args) ds = va_arg (args, XML *); if (!ds) { xml_set (ad->parms, "error", "No datasheet given."); return (XML *) 0; } if (*xml_attrval (ds, "id")) { strcpy (path, xml_attrval (ad->parms, "dir")); strcat (path, xml_attrval (ds, "id")); strcat (path, ".xml"); file = fopen (path, "w"); } else { /* Find a unique ID. */ strcpy (path, xml_attrval (ad->parms, "dir")); strcat (path, "index"); if (stat (path, &statbuf) == -1) { _index = fopen (path, "w"); if (!_index) { xml_set (ad->parms, "error", "Unable to create index file."); return (XML *) 0; } index = xml_create ("index"); } else { _index = fopen (path, "r+"); if (_index) { index = xml_read (_index); rewind (_index); } else { xml_set (ad->parms, "error", "Unable to create index file."); return (XML *) 0; } } if (!index) { xml_set (ad->parms, "error", "Directory index file corrupt."); return (XML *) 0; } if (!xml_attrval (index, "counter")) xml_set (index, "counter", "0"); counter = xml_attrvalnum (index, "counter"); do { counter ++; xml_setnum (ds, "id", counter); strcpy (path, xml_attrval (ad->parms, "dir")); strcat (path, xml_attrval (ds, "id")); strcat (path, ".xml"); } while (stat (path, &statbuf) != -1); file = fopen (path, "w"); xml_setnum (index, "counter", counter); xml_write (_index, index); fclose (_index); } if (file) { xml_write (file, ds); fclose (file); } else { xml_set (ad->parms, "error", "Couldn't open file for writing."); return (XML *) 0; } return ds; }
int main (int argc, char *argv[]) { xml= xml_read(stdin); xml_prepend (xml, xml_create("boogida")); xml_write (stdout, xml); }
int main(int argc, char **argv, char **envp) { int postsize; char *xmldata, *data; xmlDocPtr doc; xmlNodePtr cur, anode; int bbdnsock; int bbdnport; char *status = NULL; struct config_t maincfg; /* Read in config file */ maincfg = maincfgopen(); bbdnport = maincfg_get_int(&maincfg, "BLDPORT"); maincfgclose(&maincfg); key_get(systemkey); char *request_method; if (!bbdn_conect(&bbdnsock, "", bbdnport)) cgi_error(500, bstrerror()); request_method = getenv("HTTP_REQUEST_METHOD")!=NULL ? strdup(getenv("HTTP_REQUEST_METHOD")) : strdup(getenv("REQUEST_METHOD")); // We will handel the post stuf our self. Set REQUEST_METHOD to GET so cgi-util ignores it. setenv("REQUEST_METHOD", "GET", 1); if (cgi_init() != CGIERR_NONE) { cgi_error(500, "Can't init cgi-util"); } /* * Either called from command line, and then we want a file. * or a http get/put * Or we are handling a web request, and getting the data from stdin. */ if ((cgi_getentrystr("method") != NULL) && (strcmp(cgi_getentrystr("method"),"rest") == 0)) { char api[100], coll[100], url[512]; char *requrle; if (getenv("REQUEST_URI") == NULL) { cgi_error(500, "Can't read REQUEST_URI"); } requrle = strdup(getenv("REQUEST_URI")); unescape_url(requrle); sscanf(requrle,"/%[a-z]/%[a-zA-Z0-9_-]/%[^?]", api, coll, url); #ifdef DEBUG fprintf(stderr, "api: \"%s\"\n",api); fprintf(stderr, "coll: \"%s\"\n",coll); fprintf(stderr, "url: \"%s\"\n",url); fprintf(stderr, "request_method: \"%s\"\n",request_method); fprintf(stderr, "reques url \"%s\"\n",getenv("REQUEST_URI")); fprintf(stderr, "reques url unescaped \"%s\"\n",requrle); #endif free(requrle); if (strcmp(request_method,"POST") == 0 || strcmp(request_method,"ADDDELAYED") == 0 || strcmp(request_method,"PUT") == 0) { if (getenv("CONTENT_LENGTH") == NULL) { cgi_error(500, "Can't read CONTENT_LENGTH"); } // Get data length postsize = atoi(getenv("CONTENT_LENGTH")); data = malloc(postsize + 1); if (data == NULL) { cgi_error(500, "Can't allocate data."); } // Read data fread(data, 1, postsize, stdin); data[postsize] = '\0'; // add in to repo if (bbdn_docadd(bbdnsock, coll, // collection name url, // url cgi_getentrystr("documenttype"), // document type data, // data postsize, // data size 0, // lastmodified cgi_getentrystr("acl_allow")!=NULL ? cgi_getentrystr("acl_allow") : "Everyone", // acl allow cgi_getentrystr("acl_denied"), // acl denied cgi_getentrystr("title"), // title cgi_getentrystr("documentformat"), // document format cgi_getentrystr("attributes"), // attributes NULL, // image 0 // image size ) != 1) { cgi_error(500, "bbdn_docadd() failed. Can't add document."); } if (strcmp(request_method,"ADDDELAYED") != 0) { // close it sd_close(bbdnsock, coll); } asprintf(&status,"Added %s to %s\n",url,coll); } else if (strcmp(request_method,"DELETE") == 0) { if (url[0] == '\0') { if (sd_deletecollection(bbdnsock, coll) != 1) { cgi_error(500, "Can't delete collection"); } asprintf(&status,"Deleted collection %s\n",coll); } else { if (bbdn_deleteuri(bbdnsock, coll, url) != 1) { cgi_error(500, "Can't delete document"); } asprintf(&status,"Deleted url %s in %s\n",url,coll); } } else if (strcmp(request_method,"CLOSE") == 0) { sd_close(bbdnsock, coll); asprintf(&status,"Closed %s\n",coll); } else { cgi_error(500, "Unknown request method \"%s\"", request_method ); } #ifdef DEBUG // Print the envirement so we can better see what is going on. char** env; for (env = envp; *env != 0; env++) { char* thisEnv = *env; fprintf(stderr, "%s\n", thisEnv); } #endif } else if ((cgi_getentrystr("do") != NULL) && (strcmp(cgi_getentrystr("do"),"add") == 0)) { char *data; int datasize; int n; const char *url = getenv("HTTP_X_FILENAME") ? getenv("HTTP_X_FILENAME") : cgi_getentrystr("url"); const char *coll = cgi_getentrystr("collection"); if (url == NULL) { cgi_error(500, "No url specified. Either set http header HTTP_X_FILENAME or get parameter 'url'.\n"); } if (coll == NULL) { cgi_error(500, "No collection specified\n"); } char *tmpname; FILE *fh; asprintf(&tmpname,"/tmp/%s",url); fh = fopen(tmpname,"wb"); if (fh == NULL) { cgi_error(500, "Can't open file %s",tmpname); } if ((data = malloc( atoi(getenv("CONTENT_LENGTH")) )) == NULL) { cgi_error(500, "Can't malloc data"); } datasize = 0; while ((n = fread ((unsigned char *)(data + datasize),1,1024,stdin)) > 0) { datasize += n; } fwrite(data,1,datasize,fh); fclose(fh); free(tmpname); // bbdn_docadd(bbdnsock, xmldoc.collection, uri, xmldoc.documenttype, xmldoc.body, xmldoc.bodysize, // xmldoc.lastmodified, xmldoc.aclallow, xmldoc.acldeny, xmldoc.title, xmldoc.documentformat, xmldoc.attributes, image, image_size); bbdn_docadd(bbdnsock, coll, url, "", data, datasize, 0, "Everyone", "", "omp1", "", "", NULL, 0); // close it sd_close(bbdnsock, coll); } else if ((cgi_getentrystr("do") != NULL) && (strcmp(cgi_getentrystr("do"),"delete") == 0)) { const char *url = getenv("HTTP_X_FILENAME") ? getenv("HTTP_X_FILENAME") : cgi_getentrystr("url"); const char *coll = cgi_getentrystr("collection"); if (url == NULL) { cgi_error(500, "No url specified. Either set http header HTTP_X_FILENAME or get parameter 'url'.\n"); } if (coll == NULL) { cgi_error(500, "No collection specified\n"); } bbdn_deleteuri(bbdnsock, coll, url); asprintf(&status,"%s deleted.\n", url); } else if (getenv("CONTENT_LENGTH") != NULL) { // Get data length postsize = atoi(getenv("CONTENT_LENGTH")); xmldata = malloc(postsize + 1); // Read data fread(xmldata, 1, postsize, stdin); xmldata[postsize] = '\0'; //fprintf(stderr, "Received %i bytes.\n", postsize); //fprintf(stderr, "Got document:\n%s\n", xmldata); //parsing xml doc = xmlParseDoc((xmlChar*)xmldata); if (doc == NULL) cgi_error(500, "Unable to parse document"); cur = xmlDocGetRootElement(doc); if (cur == NULL) { xmlFreeDoc(doc); cgi_error(500, "empty document"); } // Some document checking if (xmlStrcmp(cur->name, (const xmlChar *)ROOT_NODE_NAME)) { xmlFreeDoc(doc); cgi_error(500, "document of the wrong type, root node != %s, but %s\n", ROOT_NODE_NAME, cur->name); } if ((anode = xml_find_child(cur, "key")) != NULL) { char *p; p = (char *)xmlNodeListGetString(doc, anode->xmlChildrenNode, 1); if (p == NULL) cgi_error(500, "No key data"); if ((systemkey[0] != '\0') && (!key_equal(systemkey, p))) { cgi_error(500, "Keys does not match: Got \"%s\" but wanted \"%s\"\n",p,systemkey); } } else { cgi_error(500, "Did not receive a key"); } if ((anode = xml_find_child(cur, "version")) != NULL) { xmlChar *p; p = xmlNodeListGetString(doc, anode->xmlChildrenNode, 1); version = atoi((char*)p); xmlFree(p); } else { cgi_error(500, "Did not receive a version number"); } for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) { if ((!xmlStrcmp(cur->name, (const xmlChar *) "key"))){ // Ignore } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "version"))){ // Ignore } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "add"))){ xml_add(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "delete"))){ xml_delete(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "close"))) { xml_close(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "create"))) { xml_create(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "users"))) { xml_users(doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "gcwhispers"))) { xml_gcwhispers(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (const xmlChar *) "error"))) { xml_errormsg(bbdnsock, doc, cur); } else if ((!xmlStrcmp(cur->name, (xmlChar*)"text"))) { //fprintf(stderr, "Got text: %s\n", xmlNodeListGetString(doc, cur, 1)); // Ignore for now } else { warnx("Unknown xml node '%s'", cur->name); } } } else { cgi_error(500, "Didn't receive any command or data."); } if (status != NULL) { printf("Content-type: text/plain\n\n"); printf(status); } else { cgi_error(500, "Reached end of program without status."); } return 0; }
agent * create_soar_agent (char * agent_name) { /* loop index */ char cur_path[MAXPATHLEN]; /* AGR 536 */ //agent* newAgent = static_cast<agent *>(malloc(sizeof(agent))); agent* newAgent = new agent(); newAgent->current_tc_number = 0; newAgent->name = savestring(agent_name); /* mvp 5-17-94 */ newAgent->variables_set = NIL; //#ifdef _WINDOWS // newAgent->current_line[0] = 0; // newAgent->current_line_index = 0; //#endif /* _WINDOWS */ newAgent->all_wmes_in_rete = NIL; newAgent->alpha_mem_id_counter = 0; newAgent->alternate_input_string = NIL; newAgent->alternate_input_suffix = NIL; newAgent->alternate_input_exit = FALSE;/* Soar-Bugs #54 */ newAgent->backtrace_number = 0; newAgent->beta_node_id_counter = 0; newAgent->bottom_goal = NIL; newAgent->changed_slots = NIL; newAgent->chunk_count = 1; newAgent->chunk_free_problem_spaces = NIL; newAgent->chunky_problem_spaces = NIL; /* AGR MVL1 */ strcpy(newAgent->chunk_name_prefix,"chunk"); /* ajc (5/14/02) */ newAgent->context_slots_with_changed_acceptable_preferences = NIL; newAgent->current_file = NIL; newAgent->current_phase = INPUT_PHASE; newAgent->applyPhase = FALSE; newAgent->current_symbol_hash_id = 0; newAgent->current_variable_gensym_number = 0; newAgent->current_wme_timetag = 1; newAgent->default_wme_depth = 1; /* AGR 646 */ newAgent->disconnected_ids = NIL; newAgent->existing_output_links = NIL; newAgent->output_link_changed = FALSE; /* KJC 11/9/98 */ /* newAgent->explain_flag = FALSE; */ newAgent->go_number = 1; newAgent->go_type = GO_DECISION; newAgent->init_count = 0; newAgent->rl_init_count = 0; newAgent->grounds_tc = 0; newAgent->highest_goal_whose_context_changed = NIL; newAgent->ids_with_unknown_level = NIL; newAgent->input_period = 0; /* AGR REW1 */ newAgent->input_cycle_flag = TRUE; /* AGR REW1 */ newAgent->justification_count = 1; newAgent->lex_alias = NIL; /* AGR 568 */ newAgent->link_update_mode = UPDATE_LINKS_NORMALLY; newAgent->locals_tc = 0; newAgent->max_chunks_reached = FALSE; /* MVP 6-24-94 */ newAgent->mcs_counter = 1; newAgent->memory_pools_in_use = NIL; newAgent->ms_assertions = NIL; newAgent->ms_retractions = NIL; newAgent->num_existing_wmes = 0; newAgent->num_wmes_in_rete = 0; newAgent->potentials_tc = 0; newAgent->prev_top_state = NIL; newAgent->print_prompt_flag = TRUE; newAgent->printer_output_column = 1; newAgent->production_being_fired = NIL; newAgent->productions_being_traced = NIL; newAgent->promoted_ids = NIL; newAgent->reason_for_stopping = "Startup"; newAgent->slots_for_possible_removal = NIL; newAgent->stop_soar = TRUE; newAgent->system_halted = FALSE; newAgent->token_additions = 0; newAgent->top_dir_stack = NIL; /* AGR 568 */ newAgent->top_goal = NIL; newAgent->top_state = NIL; newAgent->wmes_to_add = NIL; newAgent->wmes_to_remove = NIL; newAgent->wme_filter_list = NIL; /* Added this to avoid access violation -AJC (5/13/02) */ newAgent->multi_attributes = NIL; /* REW: begin 09.15.96 */ newAgent->did_PE = FALSE; newAgent->soar_verbose_flag = FALSE; newAgent->FIRING_TYPE = IE_PRODS; newAgent->ms_o_assertions = NIL; newAgent->ms_i_assertions = NIL; /* REW: end 09.15.96 */ newAgent->postponed_assertions = NIL; /* REW: begin 08.20.97 */ newAgent->active_goal = NIL; newAgent->active_level = 0; newAgent->previous_active_level = 0; /* Initialize Waterfall-specific lists */ newAgent->nil_goal_retractions = NIL; /* REW: end 08.20.97 */ /* REW: begin 10.24.97 */ newAgent->waitsnc = FALSE; newAgent->waitsnc_detect = FALSE; /* REW: end 10.24.97 */ /* Initializing rete stuff */ for (int i=0; i < 256; i++) { newAgent->actual[i]=0; newAgent->if_no_merging[i]=0; newAgent->if_no_sharing[i]=0; } /* Initializing lexeme */ newAgent->lexeme.type = NULL_LEXEME; newAgent->lexeme.string[0] = 0; newAgent->lexeme.length = 0; newAgent->lexeme.int_val = 0; newAgent->lexeme.float_val = 0.0; newAgent->lexeme.id_letter = 'A'; newAgent->lexeme.id_number = 0; reset_max_stats(newAgent); newAgent->real_time_tracker = 0; newAgent->attention_lapse_tracker = 0; if(!getcwd(cur_path, MAXPATHLEN)) print(newAgent, "Unable to set current directory while initializing agent.\n"); newAgent->top_dir_stack = static_cast<dir_stack_struct *>(malloc(sizeof(dir_stack_struct))); /* AGR 568 */ newAgent->top_dir_stack->directory = static_cast<char *>(malloc(MAXPATHLEN*sizeof(char))); /* AGR 568 */ newAgent->top_dir_stack->next = NIL; /* AGR 568 */ strcpy(newAgent->top_dir_stack->directory, cur_path); /* AGR 568 */ /* changed all references of 'i', a var belonging to a previous for loop, to 'productionTypeCounter' to be unique stokesd Sept 10 2004*/ for (int productionTypeCounter=0; productionTypeCounter<NUM_PRODUCTION_TYPES; productionTypeCounter++) { newAgent->all_productions_of_type[productionTypeCounter] = NIL; newAgent->num_productions_of_type[productionTypeCounter] = 0; } newAgent->o_support_calculation_type = 4; /* KJC 7/00 */ // changed from 3 to 4 by voigtjr (/* bugzilla bug 339 */) newAgent->numeric_indifferent_mode = NUMERIC_INDIFFERENT_MODE_SUM; /* JC ADDED: Make sure that the RHS functions get initialized correctly */ newAgent->rhs_functions = NIL; // JRV: Allocates data for XML generation xml_create( newAgent ); soar_init_callbacks( newAgent ); // // This call is needed to set up callbacks. init_memory_utilities(newAgent); // // This was moved here so that system parameters could // be set before the agent was initialized. init_sysparams (newAgent); /* Initializing all the timer structures */ // Timers must be initialized after sysparams #ifndef NO_TIMING_STUFF newAgent->timers_cpu.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED])); newAgent->timers_kernel.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED])); newAgent->timers_phase.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED])); #ifdef DETAILED_TIMING_STATS newAgent->timers_gds.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED])); #endif reset_timers(newAgent); #endif // dynamic memory pools (should come before consumers of dynamic pools) newAgent->dyn_memory_pools = new std::map< size_t, memory_pool* >(); // dynamic counters newAgent->dyn_counters = new std::map< std::string, uint64_t >(); // exploration initialization newAgent->exploration_params[ EXPLORATION_PARAM_EPSILON ] = exploration_add_parameter( 0.1, &exploration_validate_epsilon, "epsilon" ); newAgent->exploration_params[ EXPLORATION_PARAM_TEMPERATURE ] = exploration_add_parameter( 25, &exploration_validate_temperature, "temperature" ); // rl initialization newAgent->rl_params = new rl_param_container( newAgent ); newAgent->rl_stats = new rl_stat_container( newAgent ); newAgent->rl_prods = new rl_production_memory(); rl_initialize_template_tracking( newAgent ); // select initialization newAgent->select = new select_info; select_init( newAgent ); // predict initialization newAgent->prediction = new std::string(); predict_init( newAgent ); // wma initialization newAgent->wma_params = new wma_param_container( newAgent ); newAgent->wma_stats = new wma_stat_container( newAgent ); newAgent->wma_timers = new wma_timer_container( newAgent ); #ifdef USE_MEM_POOL_ALLOCATORS newAgent->wma_forget_pq = new wma_forget_p_queue( std::less< wma_d_cycle >(), soar_module::soar_memory_pool_allocator< std::pair< wma_d_cycle, wma_decay_set* > >( newAgent ) ); newAgent->wma_touched_elements = new wma_pooled_wme_set( std::less< wme* >(), soar_module::soar_memory_pool_allocator< wme* >( newAgent ) ); newAgent->wma_touched_sets = new wma_decay_cycle_set( std::less< wma_d_cycle >(), soar_module::soar_memory_pool_allocator< wma_d_cycle >( newAgent ) ); #else newAgent->wma_forget_pq = new wma_forget_p_queue(); newAgent->wma_touched_elements = new wma_pooled_wme_set(); newAgent->wma_touched_sets = new wma_decay_cycle_set(); #endif newAgent->wma_initialized = false; newAgent->wma_tc_counter = 2; // epmem initialization newAgent->epmem_params = new epmem_param_container( newAgent ); newAgent->epmem_stats = new epmem_stat_container( newAgent ); newAgent->epmem_timers = new epmem_timer_container( newAgent ); newAgent->epmem_db = new soar_module::sqlite_database(); newAgent->epmem_stmts_common = NULL; newAgent->epmem_stmts_graph = NULL; newAgent->epmem_node_mins = new std::vector<epmem_time_id>(); newAgent->epmem_node_maxes = new std::vector<bool>(); newAgent->epmem_edge_mins = new std::vector<epmem_time_id>(); newAgent->epmem_edge_maxes = new std::vector<bool>(); newAgent->epmem_id_repository = new epmem_parent_id_pool(); newAgent->epmem_id_replacement = new epmem_return_id_pool(); newAgent->epmem_id_ref_counts = new epmem_id_ref_counter(); // debug module settings newAgent->debug_params = new debug_param_container( newAgent ); #ifdef USE_MEM_POOL_ALLOCATORS newAgent->epmem_node_removals = new epmem_id_removal_map( std::less< epmem_node_id >(), soar_module::soar_memory_pool_allocator< std::pair< epmem_node_id, bool > >( newAgent ) ); newAgent->epmem_edge_removals = new epmem_id_removal_map( std::less< epmem_node_id >(), soar_module::soar_memory_pool_allocator< std::pair< epmem_node_id, bool > >( newAgent ) ); newAgent->epmem_wme_adds = new epmem_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) ); newAgent->epmem_promotions = new epmem_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) ); newAgent->epmem_id_removes = new epmem_symbol_stack( soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) ); #else newAgent->epmem_node_removals = new epmem_id_removal_map(); newAgent->epmem_edge_removals = new epmem_id_removal_map(); newAgent->epmem_wme_adds = new epmem_symbol_set(); newAgent->epmem_promotions = new epmem_symbol_set(); newAgent->epmem_id_removes = new epmem_symbol_stack(); #endif newAgent->epmem_validation = 0; // smem initialization newAgent->smem_params = new smem_param_container( newAgent ); newAgent->smem_stats = new smem_stat_container( newAgent ); newAgent->smem_timers = new smem_timer_container( newAgent ); newAgent->smem_db = new soar_module::sqlite_database(); newAgent->smem_validation = 0; #ifdef USE_MEM_POOL_ALLOCATORS newAgent->smem_changed_ids = new smem_pooled_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) ); #else newAgent->smem_changed_ids = new smem_pooled_symbol_set(); #endif newAgent->smem_ignore_changes = false; // statistics initialization newAgent->dc_stat_tracking = false; newAgent->stats_db = new soar_module::sqlite_database(); newAgent->substate_break_level = 0; return newAgent; }