IOResult PolyOperation::LoadBasics (ILoad *iload) { IOResult res; ULONG nb; int id; while (IO_OK==(res=iload->OpenChunk())) { switch (iload->CurChunkID ()) { case kSelection: res = mSelection.Load (iload); break; case kParameter: res = iload->Read (&id, sizeof(int), &nb); if (res != IO_OK) break; void *prmtr = Parameter(id); if (prmtr == NULL) return IO_ERROR; res = iload->Read (prmtr, ParameterSize(id), &nb); break; } iload->CloseChunk(); if (res!=IO_OK) return res; } return IO_OK; }
void PolyOperation::CopyBasics (PolyOperation *pCopyTo) { pCopyTo->mSelection = mSelection; Tab<int> paramList; GetParameters (paramList); for (int i=0; i<paramList.Count (); i++) { int id = paramList[i]; memcpy (pCopyTo->Parameter(id), Parameter(id), ParameterSize(id)); } }
void gcopy(genotype dest, const genotype src) { int i; size_t row = 1 + ParameterSize(src[0]) + InternalSize(src[0]) + ExternalSize(src[0]) + HideSize(src[0]); for(i = 0; i < row; i++) { dest[i] = 0x0; dest[i] = src[i]; } }
int save_ngtype(size_t population, const int type, /* 0:feature, 1:class */ const genotype *gtype) { int i; char dates[256]; FILE *gtype_fp; char rfcn_sign[4], gtype_path[1024]; size_t gtype_t_size, population_size; size_t gtype_row; bzero((void *)rfcn_sign, sizeof(rfcn_sign)); bzero((void *)dates, sizeof(dates)); bzero((void *)gtype_path, sizeof(gtype_path)); strcpy(rfcn_sign, (const char *)RFCN_SIGN); /* YYYYMMDD_hhmmss 時間文字列 */ get_date(dates); if(strlen(dates) < 2) return EOF; /* Genotype ファイルパスの取得 */ sprintf(gtype_path, "./WorkSpace/gtype/gtype_%s_%s.gtype", (type == 0 ? "feature" : "class"), dates); if((gtype_fp = fopen(gtype_path, "w")) == NULL) { perror(gtype_path); return EOF; } /* 遺伝子型の情報 */ gtype_t_size = sizeof(genotype_t); population_size = population; fwrite((const void *)rfcn_sign, sizeof(char), 4, gtype_fp); fwrite((const void *)>ype_t_size, sizeof(size_t), 1, gtype_fp); fwrite((const void *)&population_size, sizeof(size_t), 1, gtype_fp); for(i = 0; i < population; i++) { gtype_row = 1 + ParameterSize(gtype[i][0]) + InternalSize(gtype[i][0]) + ExternalSize(gtype[i][0]) + HideSize(gtype[i][0]); fwrite((const void *)gtype[i], sizeof(genotype_t), gtype_row, gtype_fp); } fclose(gtype_fp); return 0; }
IOResult PolyOperation::SaveBasics (ISave *isave) { isave->BeginChunk (kSelection); mSelection.Save (isave); isave->EndChunk (); ULONG nb; Tab<int> paramList; GetParameters (paramList); for (int i=0; i<paramList.Count (); i++) { int id = paramList[i]; isave->BeginChunk (kParameter); isave->Write (&id, sizeof(int), &nb); isave->Write (Parameter(id), ParameterSize(id), &nb); isave->EndChunk (); } return IO_OK; }
void gprint(size_t num, genotype gtype) { extern int spd[]; extern double gain[], thr[], w[]; int i, j, position; size_t column, offset; column = HideSize(gtype[0]) + OutputSize(gtype[0]); printf("[Population Number] %ld\n", num); printf("[Number of Transition] %llu\n", TransitionSize(gtype[0])); draw_line(column); printf("| |"); for(i = 0; i < HideSize(gtype[0]); i++) printf(" H%2d |", i); for(i = 0; i < OutputSize(gtype[0]); i++) printf(" O%2d |", i); printf(" 0x%010llX\n", (genotype_t)gtype[0]); draw_line(column); printf("| Function |"); for(i = 0; i < column; i++) { position = (column - i - 1) * 4; printf(" %9s |", function_name((gtype[1] >> position) & 0x0F)); } printf(" 0x%010llX\n", (genotype_t)gtype[1]); printf("| Parameter |"); for(i = 0; i < column; i++) { position = (column - i - 1) * 4; printf(" %+.2f |", gain[(gtype[2] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[2]); printf("| Speed |"); for(i = 0; i < column; i++) { position = (column - i - 1) * 4; printf(" %3d |", spd[(gtype[3] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[3]); printf("| Threshold |"); for(i = 0; i < column; i++) { position = (column - i - 1) * 4; printf(" %+.2f |", thr[(gtype[4] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[4]); draw_line(column); offset = ParameterSize(gtype[0]) + 1; for(i = 0; i < InternalSize(gtype[0]); i++) { printf("| I%2d |", i); for(j = 0; j < column; j++) { position = (column - j - 1) * 4; printf(" %+.2f |", w[(gtype[offset + i] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[offset + i]); } draw_line(column); offset += InternalSize(gtype[0]); if(ExternalSize(gtype[0]) != 0) { for(i = 0; i < ExternalSize(gtype[0]); i++) { printf("| E%2d |", i); for(j = 0; j < column; j++) { position = (column - j - 1) * 4; printf(" %+.2f |", w[(gtype[offset + i] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[offset + i]); } draw_line(column); } offset += ExternalSize(gtype[0]); for(i = 0; i < HideSize(gtype[0]); i++) { printf("| H%2d |", i); for(j = 0; j < column; j++) { position = (column - j - 1) * 4; printf(" %+.2f |", w[(gtype[offset + i] >> position) & 0x0F]); } printf(" 0x%010llX\n", (genotype_t)gtype[offset + i]); } draw_line(column); putchar('\n'); }