📄 main.c
字号:
/***************************************************************************
main.c - description
-------------------
begin : 四 4月 8 16:02:58 CST 2004
copyright : (C) 2004 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "art_int.h"
#include "art_ext.h"
/* Gets in integer value from the user */
int GetInt(void) {
char input[100];
//gets(input);
scanf("%s", input);
return atoi(input);
}
/* Gets in float value from the user */
float GetFloat(void) {
char input[100];
//gets(input);
scanf("%s", input);
return (float)(atof(input));
}
/* Gets in char value from the user */
char GetLetter(void) {
char input[100];
//gets(input);
scanf("%s", input);
return input[0];
}
void DumpNet(netPTR net) {
float vigil,beta;
if (GetNetType(net)==ART) {
printf("\t ART NETWORK:\n");
if (GetArtType(net,ART)==ART_TYPE_ART1)
printf("\t Art Type: ART_TYPE_ART1 \n");
else
printf("\t Art Type: ART_TYPE_FUZZYART \n");
printf("\t Inputs: %9i\n",GetNetInSize(net));
printf("\t Nodes: %9i\n",GetArtSize(net,ART));
GetArtVigil(net,ART,&vigil);
printf("\t Vigilance: %3.3f\n",vigil);
GetArtBeta(net,ART,&beta);
printf("\t Recoding Rate: %3.3f\n",beta);
if (GetArtStyle(net,ART)==ART_STYLE_COMPLIMENT)
printf("\t Compliment Coding: On \n");
else
printf("\t Compliment Coding: Off \n");
}
else {
GetMapVigil(net,&vigil);
printf("\t ARTMAP NETWORK: \t\t Map Vigilance: %3.3f\n",vigil);
if (GetArtType(net,ARTA)==ART_TYPE_ART1)
printf("\t ArtA Type: ART_TYPE_ART1 ");
else
printf("\t ArtA Type: ART_TYPE_FUZZYART ");
if (GetArtType(net,ARTB)==ART_TYPE_ART1)
printf("\t ArtB Type: ART_TYPE_ART1 \n");
else if (GetArtType(net,ARTB)==ART_TYPE_FUZZYART)
printf("\t ArtB Type: ART_TYPE_FUZZYART \n");
else
printf("\t ArtB Type: NONE \n");
printf("\t Inputs: %9i",GetNetInSize(net));
printf("\t Outputs: %9i\n",GetNetOutSize(net));
printf("\t Nodes: %9i",GetArtSize(net,ARTA));
printf("\t Nodes: %9i\n",GetArtSize(net,ARTB));
GetArtVigil(net,ARTA,&vigil);
printf("\t Vigilance: %3.3f",vigil);
if (GetArtType(net,ARTB)!=ART_TYPE_NONE) {
GetArtVigil(net,ARTB,&vigil);
printf("\t Vigilance: %3.3f\n",vigil);
}
else
printf("\t Vigilance: n/a\n");
GetArtBeta(net,ARTA,&beta);
printf("\t Recoding Rate: %3.3f",beta);
if (GetArtType(net,ARTB)!=ART_TYPE_NONE) {
GetArtBeta(net,ARTB,&beta);
printf("\t Recoding Rate: %3.3f\n",beta);
}
else
printf("\t Recoding Rate: n/a\n");
if (GetArtStyle(net,ARTA)==ART_STYLE_COMPLIMENT)
printf("\t Compliment Coding: On ");
else
printf("\t Compliment Coding: Off ");
if (GetArtType(net,ARTB)!=ART_TYPE_NONE) {
if (GetArtStyle(net,ARTB)==ART_STYLE_COMPLIMENT)
printf("\t Compliment Coding: On\n");
else
printf("\t Compliment Coding: Off\n");
}
else
printf("\t Compliment Coding: n/a\n");
}
}
void DumpSet(setPTR set) {
printf("\t PATTERN SET: \t\t\t Patterns: %12i\n",GetNumPatterns(set));
if (GetSetInType(set)==NODE_BINARY)
printf("\t Input Type: NODE_BINARY ");
else
printf("\t Input Type: NODE_ANALOG ");
if (GetSetOutType(set)==NODE_BINARY)
printf("\t Output Type: NODE_BINARY\n");
else if (GetSetOutType(set)==NODE_ANALOG)
printf("\t Output Type: NODE_ANALOG\n");
else
printf("\t Output Type: NONE\n");
printf("\t Input Size: %10i ",GetSetInSize(set));
if (GetSetOutType(set)!=NODE_NONE)
printf("\t Output Size: %9i\n",GetSetOutSize(set));
else
printf("\n");
}
/* Load a network from a data file */
int LoadNetwork(netPTR net) {
char file_name[80];
int status;
printf("\n\tNetwork Name: ");
//gets(file_name);
scanf("%s", file_name);
printf("\tLoading Network from %s.net\n",file_name);
status = LoadNet(net,file_name);
if (status==1) {
printf("\n\tFile %s.net not found!\n\n",file_name);
return 1;
}
if (status==2) {
printf("\n\tError! Out of memory!\n\n");
return 1;
}
return 0;
}
/* Load a pattern set from a file */
int LoadPatternSet(setPTR set) {
char file_name[80];
int status;
printf("\n\tPattern Set Name: ");
//gets(file_name);
scanf("%s", file_name);
printf("\tLoading Input/Output Patterns from %s.pat\n",file_name);
status=LoadSet(set,file_name);
if (status==1) {
printf("\n\tFile %s.pat not found!\n\n",file_name);
return 1;
}
if (status==2) {
printf("\n\tError! Out of memory!\n");
return 1;
}
return 0;
}
/* Initialize a new network, getting information from the user */
int InitNetwork(netPTR net) {
int nettype = 0;
int typeA = 0,typeB = 0;
int sizeA = 0,sizeB = 0;
int styleA = 0,styleB = 0;
int status = 0; /* Initialization status */
char input = 0;
status = TRUE;
while (status) {
printf("\tInitialize Network:\n");
printf("\tNetwork Types:");
printf("\n\t\t %i - Art",ART);
printf("\n\t\t %i - ArtMap",ARTMAP);
printf("\n\t\t What type: ");
nettype = GetInt();
printf("\n\n\t\tArt Types:");
printf("\n\t\t %i - Art1",ART_TYPE_ART1);
printf("\n\t\t %i - FuzzyArt",ART_TYPE_FUZZYART);
printf("\n\t\t What type: ");
typeA = GetInt();
printf("\t\t Input Size: ");
sizeA = GetInt();
printf("\n\n\t\tInput Styles:");
printf("\n\t\t %i - Normal",ART_STYLE_NONE);
printf("\n\t\t %i - Compliment Coded",ART_STYLE_COMPLIMENT);
printf("\n\t\t What Style: ");
styleA = GetInt();
if (nettype==ARTMAP) {
printf("\n\n\t\tTypeB Types:\n");
printf("\t\t %i - Art1\n",ART_TYPE_ART1);
printf("\t\t %i - FuzzyArt\n",ART_TYPE_FUZZYART);
printf("\t\t %i - None\n",ART_TYPE_NONE);
printf("\t\t What type: ");
typeB = GetInt();
printf("\t\t Output Size: ");
sizeB = GetInt();
if (typeB!=ART_TYPE_NONE) {
printf("\n\n\t\tOutput Styles:");
printf("\n\t\t %i - Normal",ART_STYLE_NONE);
printf("\n\t\t %i - Compliment Coded\n",ART_STYLE_COMPLIMENT);
printf("\t\t What Style: ");
styleB = GetInt();
}
else
styleB = ART_STYLE_NONE;
}
printf("\n\tInitializing network.\n\n");
status=InitNet(net,nettype,typeA,styleA,sizeA,typeB,styleB,sizeB);
if (status==5) {
printf("\n\tNetwork already initialized. Re-initialize (y/n)? ");
input=GetLetter();
if (input=='y') {
FreeNet(net);
status=InitNet(net,nettype,typeA,styleA,sizeA,typeB,styleB,sizeB);
}
else
return 1;
}
if (status==6) {
printf("\n\tError! Out of memory!\n");
return 1;
}
else if (status) {
printf("\tInitialization Error #%i! Incorrect Format.\n",status);
printf("\tTry Again (y/n)? ");
input=GetLetter();
if (input!='y')
return 1;
}
}
return 0;
}
/* Set vigilance levels according to user input */
void SetVigil(netPTR net) {
float vigil;
int type;
int status;
type=GetNetType(net);
if (type==ART) {
GetArtVigil(net,ART,&vigil);
printf("\n\t Art Vigil (%3.3f): ",vigil);
vigil = GetFloat();
status = SetArtVigil(net,ART,vigil);
if (status) {
printf("\n\tIncorrect range (%f)! Must be between 0 and 1.\n",vigil);
return;
}
}
else if (type==ARTMAP) {
GetArtVigil(net,ARTA,&vigil);
printf("\n\tArt-A Vigilance (%3.3f): ",vigil);
vigil = GetFloat();
status = SetArtVigil(net,ARTA,vigil);
if (status) {
printf("\n\tIncorrect range (%f)! Must be between 0 and 1.\n",vigil);
return;
}
if (GetArtType(net,ARTB)!=ART_TYPE_NONE) {
GetArtVigil(net,ARTB,&vigil);
printf("\tArt-B Vigilance (%3.3f): ",vigil);
vigil = GetFloat();
status=SetArtVigil(net,ARTB,vigil);
if (status) {
printf("\n\tIncorrect range (%f)! Must be between 0 and 1.\n",vigil);
return;
}
}
GetMapVigil(net,&vigil);
printf("\tMapfield Vigilance (%3.3f): ",vigil);
vigil = GetFloat();
status = SetMapVigil(net,vigil);
if (status) {
printf("\n\tIncorrect range (%f)! Must be between 0 and 1.\n",vigil);
return;
}
}
printf("\n");
}
/* Set Recoding Rate according to User Input */
void SetBeta(netPTR net) {
float beta;
int type;
int status;
type=GetNetType(net);
if (type==ART) {
GetArtBeta(net,ART,&beta);
printf("\n\n\tArt Beta (%3.3f): ",beta);
beta = GetFloat();
status = SetArtBeta(net,ART,beta);
if (status) {
printf("Incorrect range! Must be between 0 and 1.\n");
return;
}
}
else if (type==ARTMAP) {
GetArtBeta(net,ARTA,&beta);
printf("\n\n\tArt-A Beta (%3.3f): ",beta);
beta = GetFloat();
status=SetArtBeta(net,ARTA,beta);
if (status) {
printf("Incorrect range! Must be between 0 and 1.\n");
return;
}
GetArtBeta(net,ARTB,&beta);
printf("\tArt-B Beta (%3.3f): ",beta);
beta = GetFloat();
status=SetArtBeta(net,ARTB,beta);
if (status==2) {
printf("Incorrect range! Must be between 0 and 1.\n");
return;
}
else if (status) {
printf("Network needs to initialized first!\n");
return;
}
}
}
/* Merge two pattern sets */
void MergePatternSets(void) {
char set1_name[30];
char set2_name[30];
char save_name[30];
int status;
printf("\n\tFirst Pattern Set Name: ");
//gets(set1_name);
scanf("%s", set1_name);
printf("\tSecond Pattern Set Name: ");
//gets(set2_name);
scanf("%s", set2_name);
printf("\tNew Pattern Set Name: ");
//gets(save_name);
scanf("%s", save_name);
printf("\tMerging %s.pat & %s.pat into %s.pat.\n\n",
set1_name,set2_name,save_name);
status=MergeSets(set1_name,set2_name,save_name);
if (status==2)
printf("\n\tFile %s.pat not found!\n\n",set1_name);
else if (status==3)
printf("\n\tFile %s.pat not found!\n\n",set2_name);
else if (status==4)
printf("\n\tError! Out of memory!\n");
else if (status)
printf("\n\tError Merging. Incompatible Sets.\n\n");
}
/* Make pattern set */
int MakePatternSet(setPTR set) {
char file1_name[80];
char file2_name[80];
int type_inputs;
int type_outputs;
int num_inputs;
int num_outputs;
int status;
printf("\n\tInput Types:\n");
printf("\t %i - Binary\n",NODE_BINARY);
printf("\t %i - Analog\n",NODE_ANALOG);
printf("\t What type: ");
type_inputs = GetInt();
printf("\t Input Size: ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -