//--------------------------------------------------------- bool CMRVBF::On_Execute(void) { bool bUpdate; int Level; double T_Slope, Resolution, max_Resolution; CSG_Grid *pDEM, *pMRVBF, *pMRRTF, CF, VF, RF, DEM, Slope, Pctl; //----------------------------------------------------- pDEM = Parameters("DEM") ->asGrid(); pMRVBF = Parameters("MRVBF") ->asGrid(); pMRRTF = Parameters("MRRTF") ->asGrid(); T_Slope = Parameters("T_SLOPE") ->asDouble(); m_T_Pctl_V = Parameters("T_PCTL_V") ->asDouble(); m_T_Pctl_R = Parameters("T_PCTL_R") ->asDouble(); m_P_Slope = Parameters("P_SLOPE") ->asDouble(); m_P_Pctl = Parameters("P_PCTL") ->asDouble(); bUpdate = Parameters("UPDATE") ->asBool(); max_Resolution = Parameters("MAX_RES") ->asDouble() / 100.0; Resolution = SG_Get_Length(Get_System()->Get_XRange(), Get_System()->Get_YRange()); max_Resolution = max_Resolution * Resolution; //----------------------------------------------------- if( 1 ) { // DataObject_Set_Colors(pMRVBF, 100, SG_COLORS_WHITE_BLUE , false); DataObject_Set_Colors(pMRVBF, 100, SG_COLORS_RED_GREY_BLUE , false); // DataObject_Set_Colors(pMRRTF, 100, SG_COLORS_RED_GREY_BLUE , true); DataObject_Set_Colors(pMRRTF, 100, SG_COLORS_WHITE_RED , false); CSG_Grid CF, VF, RF, DEM, Slopes, Percentiles; VF.Create(*Get_System(), SG_DATATYPE_Float); RF.Create(*Get_System(), SG_DATATYPE_Float); CF.Create(*Get_System(), SG_DATATYPE_Float); CF.Assign(1.0); DEM.Create(*pDEM); //------------------------------------------------- Level = 1; Resolution = Get_Cellsize(); Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step"))); Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope)); Get_Slopes (&DEM, &Slopes); Get_Percentiles (&DEM, &Percentiles, 3); Get_Flatness (&Slopes, &Percentiles, &CF, pMRVBF, pMRRTF, T_Slope); UPDATE_VIEWS (true); //------------------------------------------------- T_Slope /= 2.0; Level++; Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step"))); Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope)); Get_Percentiles (&DEM, &Percentiles, 6); Get_Flatness (&Slopes, &Percentiles, &CF, &VF, &RF, T_Slope); Get_MRVBF (Level, pMRVBF, &VF, pMRRTF, &RF); UPDATE_VIEWS (false); //------------------------------------------------- while( Process_Get_Okay(false) && Resolution < max_Resolution ) { Resolution *= 3.0; T_Slope /= 2.0; Level++; Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step"))); Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope)); Get_Values (&DEM, &Slopes, &Percentiles, Resolution); Get_Flatness (&Slopes, &Percentiles, &CF, &VF, &RF, T_Slope); Get_MRVBF (Level, pMRVBF, &VF, pMRRTF, &RF); UPDATE_VIEWS (false); } if( Parameters("CLASSIFY")->asBool() ) { Get_Classified(pMRVBF); Get_Classified(pMRRTF); } return( true ); } return( false ); }
void evaluate(pair_t *pair) { #ifdef DEBUG int i; int x; int y; #endif int s; int a; int new_pos_x_1; int new_pos_y_1; int new_pos_x_2; int new_pos_y_2; pair->fitness_value = 0; /* for each session */ for (s = 0; s < SESSIONS_NUMBER; s++) { init_random_map(); INIT_RANDOM_POSITIONS(); /* for each action */ for (a = 0; a < ACTIONS_PER_SESSION_NUMBER; a++) { #ifdef DEBUG for (y = 0; y < MAP_HEIGHT; y++) { for (x = 0; x < MAP_WIDTH; x++) { printf( "|%c%c%c", IS_SAME_POSITION(pos_x_1, pos_y_1, x, y) ? '1' : ' ', PRINT_ITEM(GET_ITEM_INTO_MAP(x, y)), IS_SAME_POSITION(pos_x_2, pos_y_2, x, y) ? '2' : ' ' ); } printf("|\n"); } #endif /* update robbies views, indexes, actions */ UPDATE_VIEWS(); UPDATE_INDEXES(); UPDATE_ACTIONS(pair); #ifdef DEBUG printf("Robby 1: |"); for (i = 0; i < VIEW_SIZE; i++) printf("%c|", PRINT_ITEM(view_1[i])); printf( (pair->robby_1[index_1] == RANDOM_ACTION) ? " -> dna[%d] -> random: %s\n" : " -> dna[%d] -> %s\n", index_1, PRINT_ACTION(action_1) ); printf("Robby 2: |"); for (i = 0; i < VIEW_SIZE; i++) printf("%c|", PRINT_ITEM(view_2[i])); printf( (pair->robby_2[index_2] == RANDOM_ACTION) ? " -> dna[%d] -> random: %s\n" : " -> dna[%d] -> %s\n", index_2, PRINT_ACTION(action_2) ); #endif /* update robbies new positions */ new_pos_x_1 = pos_x_1; new_pos_y_1 = pos_y_1; new_pos_x_2 = pos_x_2; new_pos_y_2 = pos_y_2; UPDATE_POSITION(action_1, new_pos_x_1, new_pos_y_1); UPDATE_POSITION(action_2, new_pos_x_2, new_pos_y_2); /* evaluate robby 1 movement */ if (IS_MOVEMENT_ACTION(action_1)) { if ( (!IS_POSITION_INTO_MAP(new_pos_x_1, new_pos_y_1)) || (IS_COLLABORATIVE_VIEW && IS_SAME_POSITION(new_pos_x_1, new_pos_y_1, new_pos_x_2, new_pos_y_2)) ) pair->fitness_value -= 5; else { pos_x_1 = new_pos_x_1; pos_y_1 = new_pos_y_1; } } /* evaluate robby 2 movement */ if (IS_MOVEMENT_ACTION(action_2)) { if ( (!IS_POSITION_INTO_MAP(new_pos_x_2, new_pos_y_2)) || (IS_COLLABORATIVE_VIEW && IS_SAME_POSITION(new_pos_x_2, new_pos_y_2, new_pos_x_1, new_pos_y_1)) ) pair->fitness_value -= 5; else { pos_x_2 = new_pos_x_2; pos_y_2 = new_pos_y_2; } } /* evaluate robby 1 pick up */ if (action_1 == PICK_UP) { if (map[pos_x_1][pos_y_1] == CAN) { map[pos_x_1][pos_y_1] = EMPTY; pair->fitness_value += 10; } else pair->fitness_value -= 1; } /* evaluate robby 2 pick up */ if (action_2 == PICK_UP) { if (map[pos_x_2][pos_y_2] == CAN) { map[pos_x_2][pos_y_2] = EMPTY; pair->fitness_value += 10; } else if (action_1 != PICK_UP || !IS_SAME_POSITION(pos_x_1, pos_y_1, pos_x_2, pos_y_2)) pair->fitness_value -= 1; } #ifdef DEBUG printf("Fitness: %f\n", pair->fitness_value); #endif } #ifdef DEBUG printf("\n\n"); #endif } pair->fitness_value = (double) pair->fitness_value / (double) SESSIONS_NUMBER; }