END_TEST START_TEST(test_delete_list) { const int len = 4; struct product *l; struct product_list list; init_list(&list); fail_unless(add_product_exists(), "Delete_list: Implement add_product first!\n"); char *titles[] = {"Floppy disk", "USB stick", "Something with quite long name", "Laptop"}; const char *codes[] = {"0000", "1234567", "4444444", "1111"}; int stocks[] = {1, 2, 3, 4}; double prices[] = {0.1, 1, 10, 100}; l = add_product(&list, titles[0], codes[0], stocks[0], prices[0]); for (int i = 1; i < len; i++) { add_product(&list, titles[i], codes[i], stocks[i], prices[i]); } int ret = delete_list(&list); if (!ret) { release_list(list.head); fail("delete_list should return 1 after properly implemented\n"); } }
void create() { ::create(); set_gender( random(2)+1 ); /* OBJEDIT { */ set_spd( 11 ); set_con( 4 ); set_str( 4 ); set_dex( 14 ); set_wil( 9 ); set_cha( 15 ); set_int( 3 ); set_emp( 5 ); set_distant( "a rat" ); set_specific( "the rat" ); set_look( "It's a rat, a large, furry pest known for spreading disease and stealing grain. ~Pron is $(HP)." ); set_plural( "rats" ); set_name( "rat" ); set_type( "rodent" ); set_droppable( 1 ); set_weight( 3000 ); /* } OBJEDIT */ set_living_name( name ); set_food(query_food_capacity()); set_drink(query_drink_capacity()); set_product_aspect( C_RAT ); add_product( C_MEAT, 3, 10 ); add_product( C_PELT, 2, 20 ); //add_product( C_TAIL, 1, 10 ); set_known_forms( (["animal": ({ "bite", "dodge"}) ]) );
int main() { add_user(1, "Vinay"); add_user(2, "Sanjekar"); print_users(); add_product(1, "Macbook"); add_product(2, "iPad"); print_products(); }
void create() { object ob; ::create(); set_gender( random(2)+1 ); /* OBJEDIT { */ set_spd( 12 ); set_con( 13 ); set_str( 14 ); set_dex( 15 ); set_wil( 10 ); set_cha( 3 ); set_int( 4 ); set_emp( 3 ); set_distant( "a wolf" ); set_specific( "the wolf" ); set_look( "~Name ~verbhas gray fur, penetrating yellow eyes, and a generally surly disposition. ~Pron is $(HP)." ); set_plural( "wolves" ); set_name( "wolf" ); set_type( "wolf" ); set_droppable( 1 ); set_weight( 45000 ); /* } OBJEDIT */ set_living_name( name ); set_food(query_food_capacity()/2); set_drink(query_drink_capacity()/2); add_form("animal"); set_form("animal", 1); remove_form("brawl"); set_race("canine"); set_wc((["piercing":6])); set_wimpy(30); /* set_env_var( "skin_type", "/monsters/skin/wolf_pelt" ); set_env_var( "meat_type", "/monsters/meat/wolf" ); */ set_product_aspect( C_WOLF ); add_product( C_MEAT, 3, 40 ); add_product( C_PELT, 7, 20 ); // add_product( C_TOOTH, 4, 40 ); clone_object("/ai/carnivore")->move(this_object()); ob = clone_object("/ai/aggro"); ob->set_aggro_level(10); ob->move(this_object()); }
int __add_product(int argc, char *argv[]) { verify_number_of_parameters(argc, 5); Product *p = malloc(sizeof (Product)); p->name = argv[3]; p->category_id = atoi(argv[4]); int status = add_product(p); free(p); return status; }
void create() { ::create(); set_gender( random(2)+1 ); /* OBJEDIT { */ set_spd( 9 ); set_con( 8 ); set_str( 9 ); set_dex( 10 ); set_wil( 8 ); set_cha( 9 ); set_int( 5 ); set_emp( 7 ); set_type( "animal" ); /* } OBJEDIT */ set_living_name( name ); set_food(query_food_capacity()); set_drink(query_drink_capacity()); /* set_env_var( "skin_type", "/monsters/skin/deer_skin" ); */ set_product_aspect( C_DEER ); add_product( C_MEAT, 8, 20 ); //add_product( C_GREASE, 2, 30 ); //add_product( C_BONE, 4, 20 ); //add_product( C_HORN, 2, 10 ); add_product( C_PELT, 10, 20 ); add_form("animal"); set_form("animal", 1); remove_form("brawl"); set_race("bovine"); set_wc((["blunt":4])); set_wimpy(90); use_ai_module( "forage" ); }
END_TEST int add_product_exists() { struct product_list apu; init_list(&apu); struct product *l; l = add_product(&apu, "a", "b", 1, 2); if (l) { free(l->title); free(l); return 1; } else { return 0; } }
// read in the input file // and figure out pairs that // we want to train on void readpurchases(FILE* fp) { long long pk = 0; long id, company, brand, quantity; long customer_loc, product_loc; int parse_return; char dump[MAX_STRING+1]; // get the first line fgets(dump, MAX_STRING, fp); printf(" |\r"); while (!feof(fp)) { if ((pk*30)%INTERACTIONS==0) { printf("#"); fflush(stdout); } fgets(dump, MAX_STRING, fp); parse_return = parseline(dump, &id, &company, &brand, &quantity); if (parse_return != 0) continue; customer_loc = find_customer(id); if (customer_loc == -1) customer_loc = add_customer(id); product_loc = find_product(company, brand); if (product_loc == -1) product_loc = add_product(company, brand); for (int i=0; i<quantity; i++) { purchases[pk].custp = customers[customer_loc]; purchases[pk].prodp = products[product_loc]; pk++; if (pk > INTERACTIONS) { log_err("pk > INTERACTIONS"); exit(1); } } } printf("total pk: %lld\n", pk); }
// learn some stuff void run(FILE *fp) { clock_t start = clock(); clock_t now; int label; debug("Populating Hashes..."); long id, company, brand, quantity; rewind(fp); char dump[MAX_STRING+1]; // get the first line fgets(dump, MAX_STRING, fp); // create the temporary arrays real *custupdate = calloc(D, sizeof(real)); real *produpdate = calloc(D, sizeof(real)); real *cv; real *pv; real *randcv; real *randpv; real dot, mult; long customer_loc, product_loc; long linenum = 1; // file is in format <id,chain,dept,category,company,brand,date,productsize,productmeasure,purchasequantity,purchaseamount> while (!feof(fp)) { // get the next line from the file fgets(dump, MAX_STRING, fp); linenum++; sscanf(dump, "%ld,%*ld,%*ld,%*ld,%ld,%ld,%*25[^,],%*ld,%*30[^,],%ld,%*s", &id, &company, &brand, &quantity); quantity = 1; /* debug("Found id: %ld, company: %ld, brand: %ld", id, company, brand); */ customer_loc = find_customer(id); if (customer_loc == -1) customer_loc = add_customer(id); product_loc = find_product(company, brand); if (product_loc == -1) product_loc = add_product(company, brand); // Do the update label = 1; cv = customer_vecs + customer_loc*D; pv = product_vecs + product_loc*D; alpha = ALPHA; alpha = ALPHA * (1. - linenum / (real)(LINES + 1.)); if (alpha < ALPHA * 0.0001) alpha = ALPHA * 0.0001; /* debug("Looking at customer: %ld, product: %ld, dot: %g, mult: %g", customer_loc, product_loc, dot, mult); */ // adjust the weights dot = 0.; for (int i=0; i<D; i++) dot += cv[i]*pv[i]; mult = quantity*getmult(1., dot)*alpha; for (int i=0; i<D; i++) custupdate[i] = mult*pv[i]; for (int i=0; i<D; i++) produpdate[i] = mult*cv[i]; for (int i=0; i<quantity*NEGS; i++) { long randp = (lqrand()%PRODS); randpv = product_vecs + D*randp; // get the dot product dot = 0.; for (int i=0; i<D; i++) dot += cv[i]*randpv[i]; // get the multiplier /* mult = getmult(0., dot)*alpha/(NEGS+0.); */ mult = getmult(0., dot)*alpha; // adjust the weights for (int i=0; i<D; i++) custupdate[i] += mult*randpv[i]; for (int i=0; i<D; i++) randpv[i] += mult*cv[i]; } for (int i=0; i<quantity*NEGS; i++) { long randc = (lqrand()%CUSTS); randcv = customer_vecs + D*randc; // get the dot product dot = 0.; for (int i=0; i<D; i++) dot += randcv[i]*pv[i]; // get the multiplier /* mult = getmult(0., dot)*alpha/(NEGS+0.); */ mult = getmult(0., dot)*alpha; // adjust the weights for (int i=0; i<D; i++) produpdate[i] += mult*randcv[i]; for (int i=0; i<D; i++) randcv[i] += mult*pv[i]; } // apply updates for (int i=0; i<D; i++) cv[i] += custupdate[i]; for (int i=0; i<D; i++) pv[i] += produpdate[i]; for (int i=0; i<D; i++) if (isnan(cv[i]) || isnan(pv[i])) { log_err("We've hit a nan!!!!, linenum=%ld, line=%s", linenum, dump); exit(1); } if (linenum%10000 == 0) { /* double totcupdate = 0.; */ /* double totpupdate = 0.; */ /* for (int i=0; i<D; i++) totcupdate += custupdate[i]*custupdate[i]; */ /* for (int i=0; i<D; i++) totpupdate += produpdate[i]*produpdate[i]; */ /* double totcv = 0.; */ /* double totpv = 0.; */ /* for (int i=0; i<D; i++) totcv += cv[i]*cv[i]; */ /* for (int i=0; i<D; i++) totpv += pv[i]*pv[i]; */ /* double totcsize = 0.; */ /* double totpsize = 0.; */ /* for (long i=0; i<D*CUSTS; i++) totcsize += customer_vecs[i]*customer_vecs[i]; */ /* for (long i=0; i<D*CUSTS; i++) totpsize += product_vecs[i]*product_vecs[i]; */ now = clock(); int seconds_remaining = (int)((now - start)/(CLOCKS_PER_SEC+0.)*LINES/(linenum+0.)); int hours = seconds_remaining/(60*60); seconds_remaining -= hours*60*60; int minutes = seconds_remaining/60; seconds_remaining -= minutes*60; printf("%c%ldK lines processed. %.2f%% done. alpha=%g, num_customers=%ld, num_products=%ld. est time remaining %dh%2dm ", 13, linenum/1000, linenum/(LINES+0.)*100., alpha, num_customers, num_products, hours, minutes); /* printf("%c%ldK lines processed. %.2f%% done. alpha=%g, num_customers=%ld, num_products=%ld. est time remaining %dh%2dm, csize=%g,%g psize=%g,%g ", */ /* 13, linenum/1000, linenum/(LINES+0.)*100., alpha, num_customers, num_products, hours, minutes, */ /* sqrt(totcupdate), sqrt(totcv), */ /* /1* sqrt(totcsize), *1/ */ /* sqrt(totpupdate), sqrt(totpv) ); */ /* /1* sqrt(totpsize) ); *1/ */ fflush(stdout); } if (linenum%10000000 == 0) { FILE *fc = fopen(CUSTFILE,"w"); print_customers(fc); fclose(fc); FILE *fp = fopen(PRODFILE,"w"); print_products(fp); fclose(fp); } if (linenum>LINES-1) break; /* if (linenum > 100000) break; */ } printf("\n"); }
/* Run a GUI to select and uninstall products */ int uninstall_ui(int argc, char *argv[]) { GtkWidget *window; GtkWidget *widget; GtkWidget *frame; GtkWidget *vbox; GtkWidget *button; GtkWidget *label; const char *product_name; product_t *product; product_info_t *product_info; product_component_t *component; component_list *component_list, *addon_list; char text[1024]; #ifdef ENABLE_GTK2 // Turn off any themes setenv("GTK2_RC_FILES", "", 1); setenv("GTK_DATA_PREFIX", "", 1); #endif gtk_init(&argc,&argv); /* Disable GLib warnings that may be triggered by libglade */ g_log_set_handler ("libglade", G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION, log_handler, NULL); /* Initialize Glade */ glade_init(); uninstall_glade = GLADE_XML_NEW(DATADIR "/" UNINSTALL_GLADE, "loki_uninstall"); /* Add all signal handlers defined in glade file */ glade_xml_signal_autoconnect(uninstall_glade); /* Make sure the window is visible */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_button"); if ( widget ) { gtk_button_set_sensitive(widget, FALSE); } window = glade_xml_get_widget(uninstall_glade, "loki_uninstall"); gtk_widget_realize(window); while( gtk_events_pending() ) { gtk_main_iteration(); } /* Add emergency signal handlers */ signal(SIGHUP, main_signal_abort); signal(SIGINT, main_signal_abort); signal(SIGQUIT, main_signal_abort); signal(SIGTERM, main_signal_abort); /* Fill in the list of products and components */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox"); if ( ! widget ) { fprintf(stderr, _("No uninstall_vbox in glade file!\n")); return(-1); } gtk_container_foreach(GTK_CONTAINER(widget), empty_container, widget); for ( product_name=loki_getfirstproduct(); product_name; product_name=loki_getnextproduct() ) { /* See if we can open the product */ product = loki_openproduct(product_name); if ( ! product ) { continue; } /* See if we have permissions to remove the product */ product_info = loki_getinfo_product(product); if ( ! check_permissions(product_info, 0) ) { loki_closeproduct(product); continue; } /* Add the product and components to our list */ strncpy(text, product_info->description, sizeof(text)); frame = gtk_frame_new(text); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(widget), frame, FALSE, TRUE, 0); gtk_widget_show(frame); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show(vbox); component = loki_getdefault_component(product); component_list = NULL; if ( component ) { component_list = create_component_list(product, product_info, component); strncpy(text, _("Complete uninstall"), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)component_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)component_list); gtk_widget_show(button); } for ( component = loki_getfirst_component(product); component; component = loki_getnext_component(component) ) { if ( loki_isdefault_component(component) ) { continue; } addon_list = create_component_list(product, product_info, component); strncpy(text, loki_getname_component(component), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)addon_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)addon_list); gtk_widget_show(button); add_component_list(component_list, button); } /* Add this product to our list of open products */ add_product(product); } /* Check to make sure there's something to uninstall */ if ( ! product_list ) { label = gtk_label_new( _("No products were installed by this user.\n" "You may need to run this tool as an administrator.")); gtk_box_pack_start(GTK_BOX(widget), label, FALSE, TRUE, 0); gtk_widget_show(label); } /* Run the UI.. */ gtk_main(); /* Close all the products and return */ close_products(0); return 0; }