void opt_gradient_descent(OPTIMIZER *opt, int state) { GDDATA *gdd = opt->internal; unsigned i; /* Initialize internal state. */ if(state == 0) { gdd = opt->internal = xmalloc(sizeof(GDDATA)); gdd->d = allocate_array(1, sizeof(double), opt->size); for(i = 0; i < opt->size; i++) gdd->d[i] = 0.0; } /* Do one gradiant descent step... */ else if(state == 1) { opt_eval_grad(opt, NULL); for(i = 0; i < opt->size; i++) gdd->d[i] = opt->momentum * gdd->d[i] - opt->rate * *opt->grads[i]; if(opt->stepf) opt->stepsz = opt->stepf(opt, gdd->d, opt->stepsz); else for(i = 0; i < opt->size; i++) *opt->weights[i] += gdd->d[i]; } /* Clean up. */ else if(state == -1) { deallocate_array(gdd->d); xfree(gdd); opt->internal = NULL; } }
/** * Tests the accessor array setter. */ void test_accessor_array_setter() { void* d = *NULL_POINTER_MEMORY_MODEL; int ds = *NUMBER_100_INTEGER_MEMORY_MODEL; wchar_t* s1 = L"Huhu scheene Welt, lass' mal sehen!"; int s1c = *NUMBER_35_INTEGER_MEMORY_MODEL; int i1 = *NUMBER_0_INTEGER_MEMORY_MODEL; wchar_t* s2 = L"Erde"; int s2c = *NUMBER_4_INTEGER_MEMORY_MODEL; int i2 = *NUMBER_13_INTEGER_MEMORY_MODEL; // Allocate destination array. allocate_array((void*) &d, (void*) &ds, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"d string: %ls\n", (wchar_t*) d); fwprintf(stdout, L"s1: %ls\n", s1); fwprintf(stdout, L"s1c: %i\n", s1c); fwprintf(stdout, L"i1: %i\n", i1); replace_array(d, (void*) s1, (void*) &s1c, (void*) &i1, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"d string 2: %ls\n", (wchar_t*) d); fwprintf(stdout, L"s2: %ls\n", s2); fwprintf(stdout, L"s2c: %i\n", s2c); fwprintf(stdout, L"i2: %i\n", i2); replace_array(d, (void*) s2, (void*) &s2c, (void*) &i2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"d string 3: %ls\n", (wchar_t*) d); // Deallocate destination array. deallocate_array((void*) &d, (void*) &ds, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Tests the character array with multiple elements. */ void test_character_array_multiple_elements() { log_write_terminated_message((void*) stdout, L"Test character array multiple elements:\n"); // The destination array. void* d = *NULL_POINTER_MEMORY_MODEL; int ds = *NUMBER_22_INTEGER_MEMORY_MODEL; // Create destination array. allocate_array((void*) &d, (void*) &ds, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // The source array. wchar_t a[] = {L'T', L'h', L'i', L's', L' ', L'i', L's', L' ', L'a', L' ', L't', L'e', L's', L't', L'.', L'\n', L'\0'}; wchar_t* s = a; int ssa[] = {17}; int* ss = ssa; // The destination index to which to copy the source array. //?? overwrite_array(d, (void*) s, (void*) ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The source array for overwriting. wchar_t oa[] = {L'o', L'v', L'e', L'r', L'w', L'r', L'i', L't', L't', L'e', L'n', L'.', L'\n', L'\0'}; wchar_t* os = oa; int ossa[] = {14}; int* oss = ossa; //?? overwrite_array(d, (void*) os, (void*) oss, (void*) NUMBER_8_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The remove index. int ri = *NUMBER_12_INTEGER_MEMORY_MODEL; remove_array_elements(d, (void*) &ds, (void*) &ri, (void*) NUMBER_7_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The new array size to cut off remaining elements, // including two places for new line '\n' and c string termination '\0'. int ns = *NUMBER_15_INTEGER_MEMORY_MODEL; reallocate_array((void*) &d, (void*) &ns, (void*) &ns, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The result array. void* r = *NULL_POINTER_MEMORY_MODEL; // Test getting a reference. get_array_elements((void*) &r, d, (void*) NUMBER_8_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) r); // Destroy destination array. deallocate_array((void*) &d, (void*) &ns, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Tests the pointer array. */ void test_pointer_array() { log_write_terminated_message((void*) stdout, L"Test pointer array:\n"); // // Creation. // // The character array (including new line and null termination character). void* c = (void*) L"Hello World!"; int cs = *NUMBER_13_INTEGER_MEMORY_MODEL; fwprintf(stdout, L"c: %ls\n", (wchar_t*) c); // The pointer array. void** p = NULL_POINTER_MEMORY_MODEL; int ps = *NUMBER_1_INTEGER_MEMORY_MODEL; // Create pointer array. allocate_array((void*) &p, (void*) &ps, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"p: %i\n", p); // The result array. void** r = NULL_POINTER_MEMORY_MODEL; // // Testing. // fwprintf(stdout, L"p[0] before set: %i\n", p[0]); fwprintf(stdout, L"p[1] before set: %i\n", p[1]); // Set character array in pointer array. // Hand over character array as reference, because pointer array is expected! //?? overwrite_array(p, (void*) &c, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"p[0] after set: %i\n", p[0]); fwprintf(stdout, L"p[1] after set: %i\n", p[1]); // Get character array from pointer array. get_array_elements((void*) &r, p, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); // Print result (character array). fwprintf(stdout, L"r pointer: %i\n", *r); fwprintf(stdout, L"r string: %ls\n", (wchar_t*) *r); // // Destruction. // // Destroy pointer array. deallocate_array((void*) &p, (void*) &ps, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Tests the pointer array with null values. */ void test_pointer_array_with_null_values() { log_write_terminated_message((void*) stdout, L"Test pointer array with null values:\n"); // The pointer array. void* a = *NULL_POINTER_MEMORY_MODEL; int as = *NUMBER_5_INTEGER_MEMORY_MODEL; allocate_array((void*) &a, (void*) &as, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); /*?? TODO! overwrite_array(a, (void*) &COMMERCIAL_AT_UNICODE_CHARACTER_CODE_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(a, (void*) (void*) &NUMBER_333_INTEGER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(a, (void*) (void*) NULL_POINTER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(a, (void*) (void*) NULL_POINTER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(a, (void*) (void*) &COMMERCIAL_AT_UNICODE_CHARACTER_CODE_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); */ // The result values. char** r0 = (char**) NULL_POINTER_MEMORY_MODEL; int** r1 = (int**) NULL_POINTER_MEMORY_MODEL; void** r2 = (void**) NULL_POINTER_MEMORY_MODEL; void* r3 = *NULL_POINTER_MEMORY_MODEL; char** r4 = (char**) NULL_POINTER_MEMORY_MODEL; get_array_elements((void*) &r0, a, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); get_array_elements((void*) &r1, a, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); get_array_elements((void*) &r2, a, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); get_array_elements((void*) &r3, a, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); get_array_elements((void*) &r4, a, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"Result pointer as string r0: %s\n", *r0); fwprintf(stdout, L"Result pointer as integer r1: %i\n", **r1); fwprintf(stdout, L"Result pointer as pointer r2: %i\n", *r2); fwprintf(stdout, L"Result pointer as simple pointer r3: %i\n", r3); fwprintf(stdout, L"Result pointer as character r4: %c\n", **r4); fwprintf(stdout, L"NULL_POINTER_MEMORY_MODEL: %i \n", NULL_POINTER_MEMORY_MODEL); fwprintf(stdout, L"*NULL_POINTER_MEMORY_MODEL: %i \n", *NULL_POINTER_MEMORY_MODEL); deallocate_array((void*) &a, (void*) &as, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Tests the character array with a single element. */ void test_character_array_single_element() { log_write_terminated_message((void*) stdout, L"Test character array single element:\n"); // The character array. void* c = *NULL_POINTER_MEMORY_MODEL; int cs = *NUMBER_5_INTEGER_MEMORY_MODEL; // Create character array. allocate_array((void*) &c, (void*) &cs, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); /*?? TODO! overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_A_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_B_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_C_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(c, (void*) LINE_FEED_CONTROL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); overwrite_array(c, (void*) NULL_CONTROL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); */ // Print out array contents. log_write_terminated_message((void*) stdout, (wchar_t*) c); int i = *NUMBER_0_INTEGER_MEMORY_MODEL; wchar_t* catest = (wchar_t*) *NULL_POINTER_MEMORY_MODEL; while (*TRUE_BOOLEAN_MEMORY_MODEL) { if (i >= cs) { break; } catest = (wchar_t*) (c + i); fwprintf(stdout, L"ca: %c\n", *catest); i++; } // Destroy character array. deallocate_array((void*) &c, (void*) &cs, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
int main(int argc, char **argv) { double dt = 0.1, tau = 10.0, gain = 0.5, scale = 0.5; int steps = 400, seed = 0; OPTION opts[] = { { "-dt", OPT_DOUBLE, &dt, "time step increment" }, { "-tau", OPT_DOUBLE, &tau, "decay term" }, { "-gain", OPT_DOUBLE, &gain, "sigmoidal gain" }, { "-scale", OPT_DOUBLE, &scale, "scaling for inputs" }, { "-seed", OPT_INT, &seed, "random seed for initial state" }, { "-steps", OPT_INT, &steps, "number of time steps" }, { NULL, OPT_NULL, NULL, NULL } }; NN *nn; double *data; int i, j, k, ii, sz, n, sum; /* Get the command-line options. */ get_options(argc, argv, opts, help_string, NULL, 0); /* How many neurons? What is the N x N size? */ sz = sizeof(task_assigment_scores) / sizeof(double); n = sqrt(sz); /* Set the random seed. */ srandom(seed); /* Create the Hopfield network. */ nn = create_hopfield_net(gain, tau, dt); /* Create the input data. Note that if we changed the data for this * task assigment problem, then this would be the only thing that * would need changing for this example. */ data = create_external_input(scale, dt); for(ii = 0; ii < steps; ii++) { /* Print out the network's activation values. */ for(i = 0, k = 0; i < n; i++) { for(j = 0; j < n; j++, k++) printf("% .3f\t", nn->y[k]); printf("\n"); } printf("----------------------------------------------\n"); /* Simulate a single time step. */ nn_forward(nn, data); } /* Note that I am beeing lazy and not checking that the solution forms * a permutation matrix. */ sum = 0; for(i = 0; i < sz; i++) if(nn->y[i] > 0.5) sum += task_assigment_scores[i]; printf("\nFinal score = %d\n\n", sum); /* Free up everything. */ deallocate_array(data); nn_destroy(nn); nn_shutdown(); exit(0); }
int main(int argc, char **argv) { char *c, *cc = "Hello world! How are you! I am fine!"; short **s, *ss; double ***d, *dd; unsigned ****u, *uu; unsigned i, j, k, l, okay, aokay = 1; c = allocate_array(1, sizeof(char), strlen(cc) + 1); strcpy(c, cc); deallocate_array(c); fprintf(stderr, "%s: passed 1d char\n", argv[0]); okay = 1; s = allocate_array(2, sizeof(short), 5, 7); for(i = 0; i < 5; i++) for(j = 0; j < 7; j++) s[i][j] = i * 10 + j; ss = &s[0][0]; for(i = 0; i < 5; i++) { for(j = 0; j < 7; j++) { if(s[i][j] != i * 10 + j) { okay = 0; fprintf(stderr, "%s: failed 2d short pass 1\n", argv[0]); break; } if(s[i][j] != *ss) { okay = 0; fprintf(stderr, "%s: failed 2d short pass 2\n", argv[0]); break; } ss++; } if(!okay) break; } if(!okay) aokay = 0; else fprintf(stderr, "%s: passed 2d short\n", argv[0]); deallocate_array(s); okay = 1; d = allocate_array(3, sizeof(double), 5, 7, 3); for(i = 0; i < 5; i++) for(j = 0; j < 7; j++) for(k = 0; k < 3; k++) d[i][j][k] = i * 100 + j * 10 + k; dd = &d[0][0][0]; for(i = 0; i < 5; i++) { for(j = 0; j < 7; j++) { for(k = 0; k < 3; k++) { if(d[i][j][k] != i * 100 + j * 10 + k) { okay = 0; fprintf(stderr, "%s: failed 3d double pass 1\n", argv[0]); break; } if(d[i][j][k] != *dd) { okay = 0; fprintf(stderr, "%s: failed 2d double pass 2\n", argv[0]); break; } dd++; } if(!okay) break; } if(!okay) break; } if(!okay) aokay = 0; else fprintf(stderr, "%s: passed 3d double\n", argv[0]); deallocate_array(d); okay = 1; u = allocate_array(4, sizeof(unsigned), 5, 7, 3, 11); for(i = 0; i < 5; i++) for(j = 0; j < 7; j++) for(k = 0; k < 3; k++) for(l = 0; l < 11; l++) u[i][j][k][l] = i * 1000 + j * 100 + k * 10 + l; uu = &u[0][0][0][0]; for(i = 0; i < 5; i++) { for(j = 0; j < 7; j++) { for(k = 0; k < 3; k++) { for(l = 0; l < 11; l++) { if(u[i][j][k][l] != i * 1000 + j * 100 + k * 10 + l) { okay = 0; fprintf(stderr, "%s: failed 4d unsigned pass 1\n", argv[0]); break; } if(u[i][j][k][l] != *uu) { okay = 0; fprintf(stderr, "%s: failed 4d unsigned pass 2\n", argv[0]); break; } uu++; } if(!okay) break; } if(!okay) break; } if(!okay) break; } if(!okay) aokay = 0; else fprintf(stderr, "%s: passed 4d unsigned\n", argv[0]); deallocate_array(u); exit(!aokay); }
/** * Manages the system. * * A system lifecycle consists of the three phases: * - startup * - running * - shutdown * * in the following order: * - startup internal memory (global system parametres, e.g. for input/output) * - startup knowledge memory (statics = state knowledge + logic knowledge) * - startup signal memory (knowledge models to be executed as operations) * - create startup signal and add to signal memory * - run signal checker loop (dynamics) * - destroy startup signal * - shutdown signal memory * - shutdown knowledge memory * - shutdown internal memory * * @param p0 the run source item */ void manage(void* p0) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"\n\n"); log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Manage system."); // // Variable declaration. // // The internal memory array. void* i = *NULL_POINTER_MEMORY_MODEL; // The knowledge memory part. void* k = *NULL_POINTER_MEMORY_MODEL; // The signal memory item. void* s = *NULL_POINTER_MEMORY_MODEL; // // The signal memory interrupt request flag. // // Unix system signal handlers that return normally must modify some global // variable in order to have any effect. Typically, the variable is one that // is examined periodically by the program during normal operation. // // Whether the data in an application concerns atoms, or mere text, one has to // be careful about the fact that access to a single datum is not necessarily // atomic. This means that it can take more than one instruction to read or // write a single object. In such cases, a signal handler might be invoked in // the middle of reading or writing the object. // The usage of data types that are always accessed atomically is one way to // cope with this problem. Therefore, this flag is of type sig_atomic_t. // // Reading and writing this data type is guaranteed to happen in a single // instruction, so there's no way for a handler to run in the middle of an access. // The type sig_atomic_t is always an integer data type, but which one it is, // and how many bits it contains, may vary from machine to machine. // In practice, one can assume that int and other integer types no longer than // int are atomic, that is objects of this type are always accessed atomically. // One can also assume that pointer types are atomic; that is very convenient. // Both of these assumptions are true on all of the machines that the GNU C // library supports and on all known POSIX systems. // // Why is the keyword "volatile" used here? // // In the following example, the code sets the value stored in "foo" to 0. // It then starts to poll that value repeatedly until it changes to 255: // // static int foo; // void bar(void) { // foo = 0; // while (foo != 255); // } // // An optimizing compiler will notice that no other code can possibly // change the value stored in "foo", and will assume that it will // remain equal to "0" at all times. The compiler will therefore // replace the function body with an infinite loop similar to this: // // void bar_optimized(void) { // foo = 0; // while (true); // } // // However, foo might represent a location that can be changed // by other elements of the computer system at any time, // such as a hardware register of a device connected to the CPU. // The above code would never detect such a change; // without the "volatile" keyword, the compiler assumes that // the current program is the only part of the system that could // change the value (which is by far the most common situation). // // To prevent the compiler from optimising code as above, // the "volatile" keyword is used: // // static volatile int foo; // void bar (void) { // foo = 0; // while (foo != 255); // } // // With this modification, the loop condition will not be optimised // away, and the system will detect the change when it occurs. // volatile sig_atomic_t* signal_memory_irq = (volatile sig_atomic_t*) *NULL_POINTER_MEMORY_MODEL; // The gnu/linux console interrupt request flag. volatile sig_atomic_t* gnu_linux_console_irq = (volatile sig_atomic_t*) *NULL_POINTER_MEMORY_MODEL; // The x window system interrupt request flag. volatile sig_atomic_t* x_window_system_irq = (volatile sig_atomic_t*) *NULL_POINTER_MEMORY_MODEL; // The www service interrupt request flag. volatile sig_atomic_t* www_service_irq = (volatile sig_atomic_t*) *NULL_POINTER_MEMORY_MODEL; // The cyboi service interrupt request flag. volatile sig_atomic_t* cyboi_service_irq = (volatile sig_atomic_t*) *NULL_POINTER_MEMORY_MODEL; // The signal memory mutex. pthread_mutex_t* signal_memory_mutex = (pthread_mutex_t*) *NULL_POINTER_MEMORY_MODEL; // The gnu/linux console mutex. pthread_mutex_t* gnu_linux_console_mutex = (pthread_mutex_t*) *NULL_POINTER_MEMORY_MODEL; // The x window system mutex. pthread_mutex_t* x_window_system_mutex = (pthread_mutex_t*) *NULL_POINTER_MEMORY_MODEL; // The www service mutex. pthread_mutex_t* www_service_mutex = (pthread_mutex_t*) *NULL_POINTER_MEMORY_MODEL; // The cyboi service mutex. pthread_mutex_t* cyboi_service_mutex = (pthread_mutex_t*) *NULL_POINTER_MEMORY_MODEL; // The signal memory sleep time. double* signal_memory_sleep_time = (double*) *NULL_POINTER_MEMORY_MODEL; // The gnu linux console sleep time. double* gnu_linux_console_sleep_time = (double*) *NULL_POINTER_MEMORY_MODEL; // The x window system sleep time. double* x_window_system_sleep_time = (double*) *NULL_POINTER_MEMORY_MODEL; // The www service sleep time. double* www_service_sleep_time = (double*) *NULL_POINTER_MEMORY_MODEL; // The cyboi service sleep time. double* cyboi_service_sleep_time = (double*) *NULL_POINTER_MEMORY_MODEL; // // Variable allocation. // // Allocate internal memory array. // CAUTION! The internal memory has a pre-defined count/size, // given by the constant INTERNAL_MEMORY_MEMORY_MODEL_COUNT. allocate_array((void*) &i, (void*) INTERNAL_MEMORY_MEMORY_MODEL_COUNT, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); // Allocate knowledge memory part. allocate_part((void*) &k, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) PART_PRIMITIVE_MEMORY_ABSTRACTION); // Allocate signal memory item. allocate_item((void*) &s, (void*) NUMBER_1000_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); // Allocate signal memory interrupt request flag. signal_memory_irq = (volatile sig_atomic_t*) malloc(*VOLATILE_ATOMIC_SIGNAL_TYPE_SIZE); // Allocate gnu/linux console interrupt request flag. gnu_linux_console_irq = (volatile sig_atomic_t*) malloc(*VOLATILE_ATOMIC_SIGNAL_TYPE_SIZE); // Allocate x window system interrupt request flag. x_window_system_irq = (volatile sig_atomic_t*) malloc(*VOLATILE_ATOMIC_SIGNAL_TYPE_SIZE); // Allocate www service interrupt request flag. www_service_irq = (volatile sig_atomic_t*) malloc(*VOLATILE_ATOMIC_SIGNAL_TYPE_SIZE); // Allocate cyboi service interrupt request flag. cyboi_service_irq = (volatile sig_atomic_t*) malloc(*VOLATILE_ATOMIC_SIGNAL_TYPE_SIZE); // Allocate signal memory mutex. signal_memory_mutex = (pthread_mutex_t*) malloc(*MUTEX_THREAD_TYPE_SIZE); // Allocate gnu/linux console mutex. gnu_linux_console_mutex = (pthread_mutex_t*) malloc(*MUTEX_THREAD_TYPE_SIZE); // Allocate x window system mutex. x_window_system_mutex = (pthread_mutex_t*) malloc(*MUTEX_THREAD_TYPE_SIZE); // Allocate www service mutex. www_service_mutex = (pthread_mutex_t*) malloc(*MUTEX_THREAD_TYPE_SIZE); // Allocate cyboi service mutex. cyboi_service_mutex = (pthread_mutex_t*) malloc(*MUTEX_THREAD_TYPE_SIZE); // Allocate signal memory sleep time. signal_memory_sleep_time = (double*) malloc(*DOUBLE_REAL_TYPE_SIZE); // Allocate gnu linux console sleep time. gnu_linux_console_sleep_time = (double*) malloc(*DOUBLE_REAL_TYPE_SIZE); // Allocate x window system sleep time. x_window_system_sleep_time = (double*) malloc(*DOUBLE_REAL_TYPE_SIZE); // Allocate www service sleep time. www_service_sleep_time = (double*) malloc(*DOUBLE_REAL_TYPE_SIZE); // Allocate cyboi service sleep time. cyboi_service_sleep_time = (double*) malloc(*DOUBLE_REAL_TYPE_SIZE); // // Variable initialisation. // // Initialise signal memory interrupt request flag. *signal_memory_irq = *NUMBER_0_INTEGER_MEMORY_MODEL; // Initialise gnu/linux console interrupt request flag. *gnu_linux_console_irq = *NUMBER_0_INTEGER_MEMORY_MODEL; // Initialise x window system interrupt request flag. *x_window_system_irq = *NUMBER_0_INTEGER_MEMORY_MODEL; // Initialise www service interrupt request flag. *www_service_irq = *NUMBER_0_INTEGER_MEMORY_MODEL; // Initialise cyboi service interrupt request flag. *cyboi_service_irq = *NUMBER_0_INTEGER_MEMORY_MODEL; // // In the following mutex initialisation functions, the second parameter // specifies attributes that are to be used to initialise the mutex. // If the parameter is null, the mutex is initialised with default attributes. // // Initialise signal memory mutex. pthread_mutex_init(signal_memory_mutex, *NULL_POINTER_MEMORY_MODEL); // Initialise gnu/linux console mutex. pthread_mutex_init(gnu_linux_console_mutex, *NULL_POINTER_MEMORY_MODEL); // Initialise x window system mutex. pthread_mutex_init(x_window_system_mutex, *NULL_POINTER_MEMORY_MODEL); // Initialise www service mutex. pthread_mutex_init(www_service_mutex, *NULL_POINTER_MEMORY_MODEL); // Initialise cyboi service mutex. pthread_mutex_init(cyboi_service_mutex, *NULL_POINTER_MEMORY_MODEL); // Initialise signal memory sleep time. *signal_memory_sleep_time = *NUMBER_0_1_DOUBLE_MEMORY_MODEL; // Initialise gnu linux console sleep time. *gnu_linux_console_sleep_time = *NUMBER_0_1_DOUBLE_MEMORY_MODEL; // Initialise x window system sleep time. *x_window_system_sleep_time = *NUMBER_0_1_DOUBLE_MEMORY_MODEL; // Initialise www service sleep time. *www_service_sleep_time = *NUMBER_0_1_DOUBLE_MEMORY_MODEL; // Initialise cyboi service sleep time. *cyboi_service_sleep_time = *NUMBER_0_1_DOUBLE_MEMORY_MODEL; // // System startup. // // Start up internal memory. // // CAUTION! The internal memory items have a fixed position, // determined by constants. The items HAVE TO be assigned an // initial value, since all source code relies on them. // // Most values are compared against the *NULL_POINTER_MEMORY_MODEL constant // to find out whether they are set or not. If now initial values // would be arbitrary pointers, the program would follow a wrong path, // because it would guess that an instance was properly allocated, // while in reality the value was just an arbitrary initial one. // Therefore, such values are initialised with the well-defined *NULL_POINTER_MEMORY_MODEL. // // CAUTION! ONLY ONE parameter can be handed over to threads! // For example, the tcp socket is running in an own thread. // Therefore, the knowledge memory and signal memory NEED TO BE ADDED // to the internal memory, in order to be forwardable to threads. startup_internal_memory(i, (void*) &k, (void*) &s, (void*) &signal_memory_irq, (void*) &signal_memory_mutex, (void*) &signal_memory_sleep_time, (void*) &gnu_linux_console_irq, (void*) &gnu_linux_console_mutex, (void*) &gnu_linux_console_sleep_time, (void*) &x_window_system_irq, (void*) &x_window_system_mutex, (void*) &x_window_system_sleep_time, (void*) &www_service_irq, (void*) &www_service_mutex, (void*) &www_service_sleep_time, (void*) &cyboi_service_irq, (void*) &cyboi_service_mutex, (void*) &cyboi_service_sleep_time); // Start up system signal handler. startup_system_signal_handler(); // // System initialisation. // // Initialise system with an initial signal. initialise(s, p0, i); // // System shutdown. // // The following calls of "shutdown" procedures are just to be sure, // in case a cybol application developer has forgotten to call the // corresponding service shutdown operation in cybol logic templates. // The "interrupt" procedures are called within the "shutdown" procedures. // Shutdown gnu/linux console. maintain_shutting_gnu_linux_console(i, (void*) GNU_LINUX_CONSOLE_THREAD, (void*) GNU_LINUX_CONSOLE_EXIT); // Shutdown x window system. maintain_shutting_x_window_system(i, (void*) X_WINDOW_SYSTEM_THREAD, (void*) X_WINDOW_SYSTEM_EXIT); // Shutdown www service. maintain_shutting_socket(i, (void*) WWW_BASE_INTERNAL_MEMORY_MEMORY_NAME,(void*) WWW_SERVICE_THREAD, (void*) WWW_SERVICE_EXIT); // Shutdown cyboi service. maintain_shutting_socket(i, (void*) CYBOI_BASE_INTERNAL_MEMORY_MEMORY_NAME, (void*) CYBOI_SERVICE_THREAD, (void*) CYBOI_SERVICE_EXIT); // // Variable finalisation. // // CAUTION! Do NOT remove any internal memory internals! // The internals have a fixed position within the internal memory. // Removing them would shift all entries by one position and // thus make all entries invalid, since they could not be found // at their original index anymore. // Destroy signal memory mutex. pthread_mutex_destroy(signal_memory_mutex); // Destroy gnu/linux console mutex. pthread_mutex_destroy(gnu_linux_console_mutex); // Destroy x window system mutex. pthread_mutex_destroy(x_window_system_mutex); // Destroy www service mutex. pthread_mutex_destroy(www_service_mutex); // Destroy cyboi service mutex. pthread_mutex_destroy(cyboi_service_mutex); // // Variable deallocation. // // Deallocate signal memory interrupt request flag. free((void*) signal_memory_irq); // Deallocate gnu/linux console interrupt request flag. free((void*) gnu_linux_console_irq); // Deallocate x window system interrupt request flag. free((void*) x_window_system_irq); // Deallocate www service interrupt request flag. free((void*) www_service_irq); // Deallocate cyboi service interrupt request flag. free((void*) cyboi_service_irq); // Deallocate signal memory mutex. free((void*) signal_memory_mutex); // Deallocate gnu/linux console mutex. free((void*) gnu_linux_console_mutex); // Deallocate x window system mutex. free((void*) x_window_system_mutex); // Deallocate www service mutex. free((void*) www_service_mutex); // Deallocate cyboi service mutex. free((void*) cyboi_service_mutex); // Deallocate signal memory sleep time. free((void*) signal_memory_sleep_time); // Deallocate gnu linux console sleep time. free((void*) gnu_linux_console_sleep_time); // Deallocate x window system sleep time. free((void*) x_window_system_sleep_time); // Deallocate www service sleep time. free((void*) www_service_sleep_time); // Deallocate cyboi service sleep time. free((void*) cyboi_service_sleep_time); // Deallocate signal memory item. deallocate_item((void*) &s, (void*) NUMBER_1000_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); // Deallocate knowledge memory part. deallocate_part((void*) &k, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) PART_PRIMITIVE_MEMORY_ABSTRACTION); // Deallocate internal memory array. deallocate_array((void*) &i, (void*) INTERNAL_MEMORY_MEMORY_MODEL_COUNT, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Tests the wide character output on gnu/linux console, * in between escape control sequences. */ void test_wide_character_output() { log_write_terminated_message((void*) stdout, L"Test wide character array with termination:\n"); #ifdef GNU_LINUX_OPERATING_SYSTEM // Possible locales are: LANG, LC_CTYPE, LC_ALL. // CAUTION! This setting is necessary for UTF-8 Unicode characters to work. char* loc = setlocale(LC_ALL, ""); // The terminal (device name). FILE* t = (FILE*) *NULL_POINTER_MEMORY_MODEL; // The original termios interface. struct termios* to = (struct termios*) *NULL_POINTER_MEMORY_MODEL; // The working termios interface. struct termios* tw = (struct termios*) *NULL_POINTER_MEMORY_MODEL; // Create gnu/linux console internals. //?? allocate((void*) &t, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); to = (struct termios*) malloc(*INPUT_OUTPUT_SYSTEM_TERMINAL_TYPE_SIZE); tw = (struct termios*) malloc(*INPUT_OUTPUT_SYSTEM_TERMINAL_TYPE_SIZE); // Initialise gnu/linux console internals. // Set file stream. // CAUTION! Possibly, stdin must be used instead of stdout here! t = stdout; // Get file descriptor for file stream. int d = fileno(t); // Copy termios attributes from file descriptor. tcgetattr(d, (void*) to); tcgetattr(d, (void*) tw); // Manipulate termios attributes. tw->c_lflag &= ~ICANON; tw->c_lflag &= ~ECHO; // Set termios attributes. tcsetattr(d, TCSANOW, (void*) tw); // The terminated control sequences string. void* ts = *NULL_POINTER_MEMORY_MODEL; int tsc = *NUMBER_0_INTEGER_MEMORY_MODEL; int tss = *NUMBER_1000_INTEGER_MEMORY_MODEL; // Create terminated control sequences string. allocate_array((void*) &ts, (void*) &tss, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Set terminated control sequences string by first copying the actual // control sequences and then adding the null termination character. // (Termination character does not seem to be necessary for wide character strings.) //?? overwrite_array(ts, (void*) BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; //?? overwrite_array(ts, (void*) BOX_DRAWINGS_LIGHT_HORIZONTAL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; wprintf(L"\033[32mgreen colour\033[0mswitched off."); // \033 wchar_t wc = 0x001B; //?? overwrite_array(ts, (void*) &wc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; // [ wc = 0x005B; //?? overwrite_array(ts, (void*) &wc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; // 3 wc = 0x0033; //?? overwrite_array(ts, (void*) &wc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; // 2 wc = 0x0032; //?? overwrite_array(ts, (void*) &wc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; // m wc = 0x006d; //?? overwrite_array(ts, (void*) &wc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; //?? overwrite_array(ts, (void*) LATIN_CAPITAL_LETTER_H_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; //?? overwrite_array(ts, (void*) BOX_DRAWINGS_LIGHT_HORIZONTAL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; //?? overwrite_array(ts, (void*) BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &tsc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); tsc++; // Write to terminal. //?? fwprintf(t, L"%s\n", ts); fwprintf(t, L"%ls\n", (wchar_t*) ts); //?? log_write_terminated_message((void*) stdout, (wchar_t*) ts, t); // Destroy terminated control sequences. deallocate_array((void*) &ts, (void*) &tss, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // UTF-8 still allows you to use C1 control characters such as CSI, even // though UTF-8 also uses bytes in the range 0x80-0x9F. It is important to // understand that a terminal emulator in UTF-8 mode must apply the UTF-8 // decoder to the incoming byte stream before interpreting any control // characters. C1 characters are UTF-8 decoded just like any other character // above U+007F. // VT100 terminal emulators accept ISO 2022 (=ECMA-35) ESC sequences in // order to switch between different character sets. /*?? char c = 67; if (c < 0x80) { putchar(c); } else if (c < 0x800) { putchar(0xC0 | c >> 6); putchar(0x80 | c & 0x3F); } else if (c < 0x10000) { putchar(0xE0 | c >> 12); putchar(0x80 | c >> 6 & 0x3F); putchar(0x80 | c & 0x3F); } else if (c < 0x200000) { putchar(0xF0 | c >> 18); putchar(0x80 | c >> 12 & 0x3F); putchar(0x80 | c >> 6 & 0x3F); putchar(0x80 | c & 0x3F); } */ #endif }
/** * Tests the part. */ void test_copier_part() { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Test copier part."); // The parts. void* w = *NULL_POINTER_MEMORY_MODEL; void* p1 = *NULL_POINTER_MEMORY_MODEL; void* p2 = *NULL_POINTER_MEMORY_MODEL; // Allocate parts. allocate_part((void*) &w, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); allocate_part((void*) &p1, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); allocate_part((void*) &p2, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Fill whole. overwrite_part_element(w, (void*) L"test", (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) NAME_PART_MEMORY_NAME); overwrite_part_element(w, (void*) PART_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PART_MEMORY_ABSTRACTION_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) ABSTRACTION_PART_MEMORY_NAME); // Fill part one. overwrite_part_element(p1, (void*) L"blu", (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) NAME_PART_MEMORY_NAME); overwrite_part_element(p1, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) ABSTRACTION_PART_MEMORY_NAME); overwrite_part_element(p1, (void*) L"Hello", (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) NUMBER_5_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) MODEL_PART_MEMORY_NAME); // Fill part two. overwrite_part_element(p2, (void*) L"bla", (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) NAME_PART_MEMORY_NAME); overwrite_part_element(p2, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) ABSTRACTION_PART_MEMORY_NAME); overwrite_part_element(p2, (void*) L"World", (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) NUMBER_5_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) MODEL_PART_MEMORY_NAME); // Add two parts to whole. overwrite_part_element(w, (void*) &p1, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) MODEL_PART_MEMORY_NAME); overwrite_part_element(w, (void*) &p2, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) MODEL_PART_MEMORY_NAME); // insert_part(w, (void*) &p2, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT); // // Get one of two parts from the whole. // In this case, the second part (with index 1) is retrieved. // // The part retrieved as reference. void* p = *NULL_POINTER_MEMORY_MODEL; // The part elements retrieved as reference. void* n = *NULL_POINTER_MEMORY_MODEL; void* a = *NULL_POINTER_MEMORY_MODEL; void* m = *NULL_POINTER_MEMORY_MODEL; void* d = *NULL_POINTER_MEMORY_MODEL; // The part elements data, count retrieved as reference. void* nd = *NULL_POINTER_MEMORY_MODEL; void* nc = *NULL_POINTER_MEMORY_MODEL; void* ad = *NULL_POINTER_MEMORY_MODEL; void* ac = *NULL_POINTER_MEMORY_MODEL; void* md = *NULL_POINTER_MEMORY_MODEL; void* mc = *NULL_POINTER_MEMORY_MODEL; void* dd = *NULL_POINTER_MEMORY_MODEL; void* dc = *NULL_POINTER_MEMORY_MODEL; // Get part with index 1 from whole. get_part_element((void*) &p, w, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) MODEL_PART_MEMORY_NAME); // Get part elements. copy_array_forward((void*) &n, p, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) NAME_PART_MEMORY_NAME); copy_array_forward((void*) &a, p, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) ABSTRACTION_PART_MEMORY_NAME); copy_array_forward((void*) &m, p, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) MODEL_PART_MEMORY_NAME); copy_array_forward((void*) &d, p, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) DETAILS_PART_MEMORY_NAME); // Get part elements data, count retrieved as reference. copy_array_forward((void*) &nd, n, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) DATA_ITEM_MEMORY_NAME); copy_array_forward((void*) &nc, n, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) COUNT_ITEM_MEMORY_NAME); copy_array_forward((void*) &ad, a, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) DATA_ITEM_MEMORY_NAME); copy_array_forward((void*) &ac, a, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) COUNT_ITEM_MEMORY_NAME); copy_array_forward((void*) &md, m, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) DATA_ITEM_MEMORY_NAME); copy_array_forward((void*) &mc, m, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) COUNT_ITEM_MEMORY_NAME); copy_array_forward((void*) &dd, d, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) DATA_ITEM_MEMORY_NAME); copy_array_forward((void*) &dc, d, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) COUNT_ITEM_MEMORY_NAME); fwprintf(stdout, L"TEST nd: %ls\n", (wchar_t*) nd); fwprintf(stdout, L"TEST nc: %i\n", *((int*) nc)); fwprintf(stdout, L"TEST ad: %ls\n", (wchar_t*) ad); fwprintf(stdout, L"TEST ac: %i\n", *((int*) ac)); fwprintf(stdout, L"TEST md: %ls\n", (wchar_t*) md); fwprintf(stdout, L"TEST mc: %i\n", *((int*) mc)); fwprintf(stdout, L"TEST dd: %i\n", dd); fwprintf(stdout, L"TEST dc: %i\n", *((int*) dc)); // // Encode and output part as model diagram. // // The model diagram. void* mdi = *NULL_POINTER_MEMORY_MODEL; int mdic = *NUMBER_0_INTEGER_MEMORY_MODEL; int mdis = *NUMBER_0_INTEGER_MEMORY_MODEL; // The multibyte character stream. void* mb = *NULL_POINTER_MEMORY_MODEL; int mbc = *NUMBER_0_INTEGER_MEMORY_MODEL; int mbs = *NUMBER_0_INTEGER_MEMORY_MODEL; // The file name. void* fn = L"TEST_COPIER_TESTER.txt"; int fnc = *NUMBER_22_INTEGER_MEMORY_MODEL; int fns = *NUMBER_23_INTEGER_MEMORY_MODEL; // Allocate model diagram. allocate_array((void*) &mdi, (void*) &mdis, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Allocate multibyte character stream. allocate_array((void*) &mb, (void*) &mbs, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Encode model into model diagram. encode_model_diagram((void*) &mdi, (void*) &mdic, (void*) &mdis, w); // Encode model diagram into multibyte character stream. encode_utf_8_unicode_character_vector((void*) &mb, (void*) &mbc, (void*) &mbs, mdi, (void*) &mdic); // Write multibyte character stream as message to file system. send_file((void*) &fn, (void*) &fnc, (void*) &fns, mb, (void*) &mbc); // Deallocate model diagram. deallocate_array((void*) &mdi, (void*) &mdis, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Deallocate multibyte character stream. deallocate_array((void*) &mb, (void*) &mbs, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Deallocate parts. deallocate_part((void*) &p1, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); deallocate_part((void*) &p2, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); deallocate_part((void*) &w, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Builds a list name. * * Expected parameters: * - ?? (required): ?? (description) * * @param p0 the parameters * @param p1 the parameters count * @param p2 the knowledge memory * @param p3 the knowledge memory count * @param p4 the knowledge memory size */ void memorise_building(void* p0, void* p1, void* p2, void* p3, void* p4) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Build list name."); // The basisname name, abstraction, model, details. void** bnn = NULL_POINTER_MEMORY_MODEL; void** bnnc = NULL_POINTER_MEMORY_MODEL; void** bnns = NULL_POINTER_MEMORY_MODEL; void** bna = NULL_POINTER_MEMORY_MODEL; void** bnac = NULL_POINTER_MEMORY_MODEL; void** bnas = NULL_POINTER_MEMORY_MODEL; void** bnm = NULL_POINTER_MEMORY_MODEL; void** bnmc = NULL_POINTER_MEMORY_MODEL; void** bnms = NULL_POINTER_MEMORY_MODEL; void** bnd = NULL_POINTER_MEMORY_MODEL; void** bndc = NULL_POINTER_MEMORY_MODEL; void** bnds = NULL_POINTER_MEMORY_MODEL; // The index name, abstraction, model, details. void** idxn = NULL_POINTER_MEMORY_MODEL; void** idxnc = NULL_POINTER_MEMORY_MODEL; void** idxns = NULL_POINTER_MEMORY_MODEL; void** idxa = NULL_POINTER_MEMORY_MODEL; void** idxac = NULL_POINTER_MEMORY_MODEL; void** idxas = NULL_POINTER_MEMORY_MODEL; void** idxm = NULL_POINTER_MEMORY_MODEL; void** idxmc = NULL_POINTER_MEMORY_MODEL; void** idxms = NULL_POINTER_MEMORY_MODEL; void** idxd = NULL_POINTER_MEMORY_MODEL; void** idxdc = NULL_POINTER_MEMORY_MODEL; void** idxds = NULL_POINTER_MEMORY_MODEL; // The result name, abstraction, model, details. void** resn = NULL_POINTER_MEMORY_MODEL; void** resnc = NULL_POINTER_MEMORY_MODEL; void** resns = NULL_POINTER_MEMORY_MODEL; void** resa = NULL_POINTER_MEMORY_MODEL; void** resac = NULL_POINTER_MEMORY_MODEL; void** resas = NULL_POINTER_MEMORY_MODEL; void** resm = NULL_POINTER_MEMORY_MODEL; void** resmc = NULL_POINTER_MEMORY_MODEL; void** resms = NULL_POINTER_MEMORY_MODEL; void** resd = NULL_POINTER_MEMORY_MODEL; void** resdc = NULL_POINTER_MEMORY_MODEL; void** resds = NULL_POINTER_MEMORY_MODEL; // get the basisname get_universal_compound_element_by_name( (void*) &bnn, (void*) &bnnc, (void*) &bnns, (void*) &bna, (void*) &bnac, (void*) &bnas, (void*) &bnm, (void*) &bnmc, (void*) &bnms, (void*) &bnd, (void*) &bndc, (void*) &bnds, p0, p1, (void*) BASE_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) BASE_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); // get the index get_universal_compound_element_by_name( (void*) &idxn, (void*) &idxnc, (void*) &idxns, (void*) &idxa, (void*) &idxac, (void*) &idxas, (void*) &idxm, (void*) &idxmc, (void*) &idxms, (void*) &idxd, (void*) &idxdc, (void*) &idxds, p0, p1, (void*) INDEX_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) INDEX_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); // get the result get_universal_compound_element_by_name( (void*) &resn, (void*) &resnc, (void*) &resns, (void*) &resa, (void*) &resac, (void*) &resas, (void*) &resm, (void*) &resmc, (void*) &resms, (void*) &resd, (void*) &resdc, (void*) &resds, p0, p1, (void*) COMPOSITION_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) COMPOSITION_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); //check the abstraction for the operation element int comp_res1 = *NUMBER_0_INTEGER_MEMORY_MODEL; int comp_res2 = *NUMBER_0_INTEGER_MEMORY_MODEL; int comp_res3 = *NUMBER_0_INTEGER_MEMORY_MODEL; // Create compare string. wchar_t* int_string = *NULL_POINTER_MEMORY_MODEL; // todo Konstante noch definieren int int_string_count = *NUMBER_0_INTEGER_MEMORY_MODEL; int int_string_size = *NUMBER_10_INTEGER_MEMORY_MODEL; allocate_array((void*) &int_string, (void*) &int_string_size, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); int_string_count = swprintf(int_string, int_string_size, L"%i", *((int*) *idxm)); // destination size *(int*)*resms = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT + int_string_count; *(int*)*resmc = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT + int_string_count; // Reallocate result array. reallocate_array(resm, *resms, *resms, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Set result array. replace_array(*resm, *bnm, *bnmc, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); replace_array(*resm, LIST_SEPARATOR_CYBOL_NAME, LIST_SEPARATOR_CYBOL_NAME_COUNT, *bnmc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); int temp_index = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT; replace_array(*resm, int_string, &int_string_count, &temp_index, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Destroy int_string array. deallocate_array((void*) &int_string, (void*) &int_string_size, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
int main(int argc, char **argv) { /* These variables are for command-line options. */ double var = 0.25, *x, **J, err; int seed = 0, nbasis = 12, points = 200, i; /* The OPTION array is used to easily parse command-line options. */ OPTION opts[] = { { "-var", OPT_DOUBLE, &var, "variance of basis functions" }, { "-seed", OPT_INT, &seed, "random number seed" }, { "-nbasis", OPT_INT, &nbasis, "number of basis functions" }, { "-points", OPT_INT, &points, "number of data points" }, { NULL, OPT_NULL, NULL, NULL } }; /* The DATASET and the NN that we will use. */ DATASET *data; NN *nn; /* Get the command-line options. */ get_options(argc, argv, opts, help_string, NULL, 0); srandom(seed); /* Make the data, and build an rbf from it. */ data = make_data(points); nn = nn_create("2 2"); nn_link(nn, "0 -q-> 1"); nn_set_actfunc(nn, 1, 0, "linear"); nn->info.train_set = data; nn->info.opt.min_epochs = 10; nn->info.opt.max_epochs = 25; nn->info.opt.error_tol = 10e-5; nn->info.opt.delta_error_tol = 10e-6; nn->info.opt.hook = training_hook; nn->info.opt.engine = opt_quasinewton_bfgs; nn_train(nn); J = allocate_array(2, sizeof(double), 2, 2); /* Now test to see of nn_jacobian() works. */ for(i = 0; i < points; i++) { x = dataset_x(data, i); nn_jacobian(nn, x, &J[0][0]); #if 0 printf("% 2.2f\t% 2.2f\t% 2.2f\t% 2.2f\n", nn->x[0], nn->x[1], nn->y[0], nn->y[1]); printf("% 2.2f\t% 2.2f\t% 2.2f\t% 2.2f\n", J[0][0], J[0][1], J[1][0], J[1][1]); printf("% 2.2f\t% 2.2f\t% 2.2f\t% 2.2f\n", df1dx1(x[0], x[1]), df1dx2(x[0], x[1]), df2dx1(x[0], x[1]), df2dx2(x[0], x[1])); printf("--\n"); #endif #if 1 err = J[0][0] - df1dx1(x[0], x[1]); err = err * err; printf("% 2.2f\t", err); err = J[0][1] - df1dx2(x[0], x[1]); err = err * err; printf("% 2.2f\t", err); err = J[1][0] - df2dx1(x[0], x[1]); err = err * err; printf("% 2.2f\t", err); err = J[1][1] - df2dx2(x[0], x[1]); err = err * err; printf("% 2.2f\n", err); #endif } /* Free up everything. */ deallocate_array(J); nn_destroy(nn); series_destroy(dataset_destroy(data)); nn_shutdown(); exit(0); }