⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generator.c

📁 利用C语言实现的人工智能系统
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* define initial time */	strcpy(sql, "INSERT INTO Times (ID, Time) VALUES (NULL, '2007-11-07-11-50-23-125-02689-54646546');");
	db_execute_sql(dbo, sql);

	/* create database indexes */
	/* Objects */
	strcpy(sql, "CREATE UNIQUE INDEX idxObjects ON Objects (ID ASC, Type ASC);");
	db_execute_sql(dbo, sql);
	
	/* Object_Properties */
	strcpy(sql, "CREATE UNIQUE INDEX idxObjectProperties ON Object_Properties (ID ASC);");
	db_execute_sql(dbop, sql);
	strcpy(sql, "CREATE INDEX idxObjectPropertyIDs ON Object_Properties (Object_ID ASC);");
	db_execute_sql(dbop, sql);
	
	/* Object_Interactions */
	strcpy(sql, "CREATE UNIQUE INDEX idxObjectInteractions ON Object_Interactions (ID ASC, Object_ID ASC);");
	db_execute_sql(dboi, sql);
	strcpy(sql, "CREATE INDEX idxObjectInteractionIDs ON Object_Interactions (Object_ID ASC);");
	db_execute_sql(dboi, sql);
	
	/* Interaction_Properties */
	strcpy(sql, "CREATE UNIQUE INDEX idxInteractionProperties ON Interaction_Properties (Object_Interaction_ID ASC, Property_ID ASC);");
	db_execute_sql(dbip, sql);

	/* Property_Values */
	strcpy(sql, "CREATE UNIQUE INDEX idxPropertyValues ON Property_Values (Object_Property_ID ASC);");
	db_execute_sql(dbpv, sql);
	strcpy(sql, "CREATE UNIQUE INDEX idxPropertyTimes ON Property_Values (Object_Property_ID ASC, Time_ID ASC);");
	db_execute_sql(dbpv, sql);
	
	/* Archive_Property_Values */
	strcpy(sql, "CREATE INDEX idxArchivePropertyValues ON Archive_Property_Values (Object_Property_ID ASC);");
	db_execute_sql(dbapv, sql);
	strcpy(sql, "CREATE UNIQUE INDEX idxArchivePropertyTimes ON Archive_Property_Values (Object_Property_ID ASC, Time_ID ASC);");
	db_execute_sql(dbapv, sql);
	/* Settings */
	strcpy(sql, "CREATE UNIQUE INDEX idxSettings ON Settings (ID ASC);");
	db_execute_sql(dbo, sql);	/* commit transactions */
	strcpy(sql, "COMMIT TRANSACTION");
	db_execute_sql(dbo, sql);

	/* free memory */	
	free(file_path);
	
	free(file_object_path);
	free(file_object_property_path);
	free(file_object_interaction_path);
	free(file_interaction_property_path);
	free(file_property_value_path);
	free(file_archive_property_value_path);

	free(sql);

	/* close database files */
	db_cache_close(file_object_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
#ifdef USE_ARCHIVE		/* archive the file */	strcpy(command, "gzip ");	strcat(command, file_object_id);		system(command);	/* execute the command */#endif}
void neuron_generator_multiple(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;
	
	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, "");
	
	if (DBG_GENERATION) printf("file_path=%s\n", file_path);
	
	/* 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 each database file */
	uuid_create(file_object_id);
	uuid_create(file_object_property_id);
	uuid_create(file_object_interaction_id);
	uuid_create(file_interaction_property_id);
	uuid_create(file_property_value_id);
	uuid_create(file_archive_property_value_id);

	xml_store_data();

	/* database id's */
	strcat(file_object_path, file_object_id);
	strcat(file_object_property_path, file_object_property_id);
	strcat(file_object_interaction_path, file_object_interaction_id);
	strcat(file_interaction_property_path, file_interaction_property_id);
	strcat(file_property_value_path, file_property_value_id);
	strcat(file_archive_property_value_path, file_archive_property_value_id);
	
	/* add database file extension */ 
	strcat(file_object_path, ".db");
	strcat(file_object_property_path, ".db");
	strcat(file_object_interaction_path, ".db");
	strcat(file_interaction_property_path, ".db");
	strcat(file_property_value_path, ".db");
	strcat(file_archive_property_value_path, ".db");
	
	/* create database files */
	db_cache_new(file_object_path, file_object_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	db_cache_new(file_object_property_path, file_object_property_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	db_cache_new(file_object_interaction_path, file_object_interaction_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	db_cache_new(file_interaction_property_path, file_interaction_property_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	db_cache_new(file_property_value_path, file_property_value_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	db_cache_new(file_archive_property_value_path, file_archive_property_value_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	
	/* Objects */
	dbo = db_cache_get(file_object_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	/* Object_Interactions */
	dboi = db_cache_get(file_object_interaction_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	/* Object_Properties */
	dbop = db_cache_get(file_object_property_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	/* Interaction_Properties */
	dbip = db_cache_get(file_interaction_property_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	/* Property_Values */
	dbpv = db_cache_get(file_property_value_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	/* Archive Property_Values */
	dbapv = db_cache_get(file_archive_property_value_id, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
	if (DBG_GENERATION)
	{
		printf("file_object_path=%s\n", file_object_path);
		printf("file_object_property_path=%s\n", file_object_property_path);
		printf("file_object_interaction_path=%s\n", file_object_interaction_path);
		printf("file_interaction_property_path=%s\n", file_interaction_property_path);
		printf("file_property_value_path=%s\n", file_property_value_path);
		printf("file_archive_property_value_path=%s\n", file_archive_property_value_path);
	}

	/* 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));

	/* create database schema */
	
	/* Objects */
	strcpy(sql, "CREATE TABLE Objects (ID INTEGER NOT NULL PRIMARY KEY);");
	db_execute_sql(dbo, sql);
	
	/* Object_Properties */
	strcpy(sql, "CREATE TABLE Object_Properties (ID INTEGER NOT NULL PRIMARY KEY, Object_ID INTEGER NOT NULL, Property_ID INTEGER NOT NULL, Unit_ID INTEGER NOT NULL);");
	db_execute_sql(dbop, sql);
	
	/* Object_Interactions */
	strcpy(sql, "CREATE TABLE Object_Interactions (Object_Interaction_ID INTEGER NOT NULL, Object_ID INTEGER NOT NULL);");
	db_execute_sql(dboi, sql);
	
	/* Interaction_Properties */
	strcpy(sql, "CREATE TABLE Interaction_Properties (Object_Interaction_ID INTEGER NOT NULL, Property_ID INTEGER NOT NULL);");
	db_execute_sql(dbip, sql);

	/* Property_Values */
	strcpy(sql, "CREATE TABLE Property_Values (Object_Property_ID INTEGER NOT NULL, Time_ID INTEGER NOT NULL, Property_Value VARCHAR(100) NOT NULL);");
	db_execute_sql(dbpv, sql);
	
	/* Archive_Property_Values */
	strcpy(sql, "CREATE TABLE Archive_Property_Values (Object_Property_ID INTEGER NOT NULL, Time_ID INTEGER NOT NULL, Property_Value VARCHAR(100) NOT NULL);");
	db_execute_sql(dbapv, sql);
	
	/* start the transaction mechanism to speed up the insert performance */
	db_transaction_count = 0;
	
	strcpy(sql, "BEGIN TRANSACTION");
	db_execute_sql(dbo, sql);
	db_execute_sql(dboi, sql);
	db_execute_sql(dbop, sql);
	db_execute_sql(dbip, sql);
	db_execute_sql(dbpv, sql);
	db_execute_sql(dbapv, sql);
	
	for (i=0; i<number_neurons; i++)
	{
		if (DBG_GENERATION) printf("i=%d db_transaction_count=%d\n", i, db_transaction_count);
		
		/* check if we reached the commit point */
		if (db_transaction_count == db_transaction_limit)
		{
			strcpy(sql, "COMMIT TRANSACTION");
			db_execute_sql(dbo, sql);
			db_execute_sql(dboi, sql);
			db_execute_sql(dbop, sql);
			db_execute_sql(dbip, sql);
			db_execute_sql(dbpv, sql);
			db_execute_sql(dbapv, sql);
			
			db_transaction_count = 0;			/* reset counter */
			
			strcpy(sql, "BEGIN TRANSACTION");
			db_execute_sql(dbo, sql);
			db_execute_sql(dboi, sql);
			db_execute_sql(dbop, sql);
			db_execute_sql(dbip, sql);
			db_execute_sql(dbpv, sql);
			db_execute_sql(dbapv, 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 (%d, %d)", object_interaction_id, object_id);
			db_execute_sql(dboi, sql);
			
			sprintf(sql, "INSERT INTO Interaction_Properties (Object_Interaction_ID, Property_ID) VALUES (%d, %d)", object_interaction_id, "68ff54756ad34491ab95aaa71dfe2c63");
			db_execute_sql(dbip, sql);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -