📄 main.c
字号:
/*
* ARTIFICIAL INTELLIGENCE SYSTEM
*
* Copyright (C) 2007-Present Intelligence Realm Inc. All rights reserved.
*
* See LICENSE.TXT document for licensing information.
*/
#include "main.h"
int main(int argc, char **argv)
{ int neuron_count = 1000; int i = 1;
db_unique_file = (char *)malloc(512 * sizeof(char)); strcpy(db_unique_file, "/home/ovi/source/aisystem/src/74bb2a7c00e84834a26847b70a772971.db"); db_unique_file_id = argv[1]; for(i=0; i<20; i++) { printf("***********************************************************************\n"); neuron_generator_unique(neuron_count); simulation_initialize();
simulation_process();
simulation_finalize(); } free(db_unique_file); return 0; }
void neuron_generator_unique(int number_neurons)
{
/*
* generate biophysical neurons; we must generate objects, interactions between objects, object properties and
* property values and each of these entities will reside in new database files
*/
db_type *dbo = NULL;
db_type *dboi = NULL;
db_type *dbop = NULL;
db_type *dbip = NULL;
db_type *dbpv = NULL;
db_type *dbapv = NULL;
db_sql *sql = NULL;
/* files UUID's */
char *file_object_id;
char *file_object_property_id;
char *file_object_interaction_id;
char *file_interaction_property_id;
char *file_property_value_id;
char *file_archive_property_value_id; char *object_id = NULL;
char *object_property_id = NULL;
char *property_id = NULL;
char *object_interaction_id = NULL;
char *interaction_property_id = NULL;
char *property_value_id = NULL;
char *archive_property_value_id = NULL;
char *file_object_path = NULL;
char *file_object_property_path = NULL;
char *file_object_interaction_path = NULL;
char *file_interaction_property_path = NULL;
char *file_property_value_path = NULL;
char *file_archive_property_value_path = NULL;
char *file_path = NULL;
int i;
/* define file path */
file_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char)); strcpy(file_path, db_unique_file);
/* allocate memory for database files ID's */
file_object_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
file_object_property_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
file_object_interaction_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
file_interaction_property_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
file_property_value_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
file_archive_property_value_id = (char *)malloc((UUID_DATA_LENGTH + 1) * sizeof(char));
/*
* we store into a list, the open databases handlers so that we can reuse them later on,
* without having to re-open a database each time we need to access its data
*/
db_cache_count = 0; /* initialize variables */
db_transaction_limit = 100;
db_transaction_count = 0;
db_cache_list = (struct db_cache_type **)malloc(1 * sizeof(struct db_cache_type *)); /* allocate memory */
file_object_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
file_object_property_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
file_object_interaction_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
file_interaction_property_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
file_property_value_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
file_archive_property_value_path = (char *)malloc((MAX_PATH_LENGTH + 1) * sizeof(char));
/* add file folder */
strcpy(file_object_path, file_path);
strcpy(file_object_property_path, file_path);
strcpy(file_object_interaction_path, file_path);
strcpy(file_interaction_property_path, file_path);
strcpy(file_property_value_path, file_path);
strcpy(file_archive_property_value_path, file_path);
/* get unique id's for the database file */
strcpy(file_object_id, db_unique_file_id);
strcpy(file_object_property_id, file_object_id);
strcpy(file_object_interaction_id, file_object_id);
strcpy(file_interaction_property_id, file_object_id);
strcpy(file_property_value_id, file_object_id);
strcpy(file_archive_property_value_id, file_object_id);
/* create database file */
db_cache_new(file_object_path, file_object_id, SQLITE_OPEN_READWRITE);
/* Objects */
dbo = db_cache_get(file_object_id, SQLITE_OPEN_READWRITE);
/* Object_Interactions */
dboi = dbo;
/* Object_Properties */
dbop = dbo;
/* Interaction_Properties */
dbip = dbo;
/* Property_Values */
dbpv = dbo;
/* Archive Property_Values */
dbapv = dbo;
/* allocate memory */
object_id = (char *)malloc((UUID_DATA_LENGTH+1) * sizeof(char));
object_property_id = (char *)malloc((UUID_DATA_LENGTH+1) * sizeof(char));
property_id = (char *)malloc((UUID_DATA_LENGTH+1) * sizeof(char));
object_interaction_id = (char *)malloc((UUID_DATA_LENGTH+1) * sizeof(char));
interaction_property_id = (char *)malloc((UUID_DATA_LENGTH+1) * sizeof(char));
property_value_id = (char *)malloc((PROPERTY_VALUE_DATA_LENGTH+1) * sizeof(char));
archive_property_value_id = (char *)malloc((PROPERTY_VALUE_DATA_LENGTH+1) * sizeof(char));
sql = (char *)malloc(500 * sizeof(char));
/* remove existing rows */
/* Objects */
strcpy(sql, "DELETE FROM Objects;");
db_execute_sql(dbo, sql);
/* Object_Properties */
strcpy(sql, "DELETE FROM Object_Properties;");
db_execute_sql(dbop, sql);
/* Object_Interactions */
strcpy(sql, "DELETE FROM Object_Interactions;");
db_execute_sql(dboi, sql);
/* Interaction_Properties */
strcpy(sql, "DELETE FROM Interaction_Properties;");
db_execute_sql(dbip, sql);
/* Property_Values */
strcpy(sql, "DELETE FROM Property_Values;");
db_execute_sql(dbpv, sql);
/* Archive_Property_Values */
strcpy(sql, "DELETE FROM Archive_Property_Values;");
db_execute_sql(dbapv, sql);
/* Settings */
strcpy(sql, "DELETE FROM Settings;");
db_execute_sql(dbo, sql);
/* start the transaction mechanism to speed up the insert performance */
db_transaction_count = 0;
strcpy(sql, "BEGIN TRANSACTION");
db_execute_sql(dbo, sql);
for (i=0; i<number_neurons; i++)
{
/* check if we reached the commit point */
if (db_transaction_count == db_transaction_limit)
{
strcpy(sql, "COMMIT TRANSACTION");
db_execute_sql(dbo, sql);
db_transaction_count = 0; /* reset counter */
strcpy(sql, "BEGIN TRANSACTION");
db_execute_sql(dbo, sql);
}
/* generate the data */
uuid_create(object_id);
sprintf(sql, "INSERT INTO Objects (ID) VALUES ('%s')", object_id);
db_execute_sql(dbo, sql);
db_transaction_count++; /* we increase the value for objects database only */
if (i % 2 == 1) /* soma */
{
/* we create a new interaction only for the first object; for the second object we will reuse the same id */
uuid_create(object_interaction_id);
sprintf(sql, "INSERT INTO Object_Interactions (Object_Interaction_ID, Object_ID) VALUES ('%s', '%s')", object_interaction_id, object_id);
db_execute_sql(dboi, sql);
sprintf(sql, "INSERT INTO Interaction_Properties (Object_Interaction_ID, Property_ID) VALUES ('%s', '%s')", object_interaction_id, "68ff54756ad34491ab95aaa71dfe2c63");
db_execute_sql(dbip, sql);
sprintf(sql, "INSERT INTO Interaction_Properties (Object_Interaction_ID, Property_ID) VALUES ('%s', '%s')", object_interaction_id, "1906704a17fa473398b7a3dae5a2b013");
db_execute_sql(dbip, sql);
sprintf(sql, "INSERT INTO Interaction_Properties (Object_Interaction_ID, Property_ID) VALUES ('%s', '%s')", object_interaction_id, "33b87fb6cf0547e793779df6ebcca013");
db_execute_sql(dbip, sql);
uuid_create(object_property_id);
sprintf(sql, "INSERT INTO Object_Properties (ID, Object_ID, Property_ID, Unit_ID) VALUES ('%s', '%s', '%s', '%s')", object_property_id, object_id, "3169342e968a4f979cb821e4419c2520", "9121a51fafd449788c563b33a9ac64ef");
db_execute_sql(dbop, sql);
sprintf(sql, "INSERT INTO Property_Values (Object_Property_ID, Time_ID, Property_Value) VALUES ('%s', '%s', '%s')", object_property_id, ID_SET_SIMULATION_TIME_STEP, "30e-4");
db_execute_sql(dbpv, sql);
uuid_create(object_property_id);
sprintf(sql, "INSERT INTO Object_Properties (ID, Object_ID, Property_ID, Unit_ID) VALUES ('%s', '%s', '%s', '%s')", object_property_id, object_id, "236c832aface444ca9805391cf9def17", "9121a51fafd449788c563b33a9ac64ef");
db_execute_sql(dbop, sql);
sprintf(sql, "INSERT INTO Property_Values (Object_Property_ID, Time_ID, Property_Value) VALUES ('%s', '%s', '%s')", object_property_id, ID_SET_SIMULATION_TIME_STEP, "30e-4");
db_execute_sql(dbpv, sql);
uuid_create(object_property_id);
sprintf(sql, "INSERT INTO Object_Properties (ID, Object_ID, Property_ID, Unit_ID) VALUES ('%s', '%s', '%s', '%s')", object_property_id, object_id, "68ff54756ad34491ab95aaa71dfe2c63", "3f905435f4824d539327c1c5cc9acc40");
db_execute_sql(dbop, sql);
sprintf(sql, "INSERT INTO Property_Values (Object_Property_ID, Time_ID, Property_Value) VALUES ('%s', '%s', '%s')", object_property_id, ID_SET_SIMULATION_TIME_STEP, "-59.4");
db_execute_sql(dbpv, sql);
uuid_create(object_property_id);
sprintf(sql, "INSERT INTO Object_Properties (ID, Object_ID, Property_ID, Unit_ID) VALUES ('%s', '%s', '%s', '%s')", object_property_id, object_id, "33b87fb6cf0547e793779df6ebcca013", "ed695ad4181347928611c6b9d2a3410e");
db_execute_sql(dbop, sql);
sprintf(sql, "INSERT INTO Property_Values (Object_Property_ID, Time_ID, Property_Value) VALUES ('%s', '%s', '%s')", object_property_id, ID_SET_SIMULATION_TIME_STEP, "0");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -