//windows
string $window = `window -title "Genetic Propagating"
-widthHeight 400 55`;
string $tabs = `tabLayout`;
string $tab1 = `columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 200`;
frameLayout -label "PolyCube" -labelAlign "center" -borderStyle "in";
rowLayout ;
iconTextButton -style "iconAndTextVertical" -image1 "cube.xpm" -w 170 -label "cube" -ann "Use this tool, you could creat a polyCube." -command
"polyCube";
setParent ..;
setParent ..;
frameLayout -label "Control Tools" -labelAlign "center" -borderStyle "out";
rowLayout -numberOfColumns 3 -columnWidth3 60 60 60 ; toolCollection;
toolButton
-tool selectSuperContext
-toolImage1 selectSuperContext "aselect.xpm" -iol select;
toolButton
-tool moveSuperContext
-toolImage1 moveSuperContext "move_M.xpm" -iol move;
toolButton
-tool scaleSuperContext
-toolImage1 scaleSuperContext "scale_M.xpm" -iol scale;
setParent ..;
setParent ..;
frameLayout -label "Random Generation" -labelAlign "center" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Propagating" -ann "Propagating the configurations." -command
"propagate($generation, $kk);";
setParent ..;
setParent ..;
frameLayout -label "Next Generation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Next Generation" -ann "Go to the Next generation." -command
"nextGeneration($generation, $kk);";
setParent ..;
setParent ..;
frameLayout -label "Control former Generation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
frameLayout -label "Information" -labelAlign "bottom" -borderStyle "etchedOut";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
text -label " This tool is created by Michael" -align "center" -font "obliqueLabelFont";
//text -label " NCTU Architecture Department" -align "center" -font
string $tab2 = `columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 200`;
frameLayout -label "Genetic Environment Settings" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Set Complex Value intended" -ann "Use this tool to set the Complex Value." -command "setComplex();";
button -label "Set PopulationSize intended" -ann "Use this tool to set the Population Size." -command "setPopulationSize();";
button -label "Propagating" -ann "Use this tool to set the parent." -command
"generGeneCode($complexValue,$populationSize,$generation);";
button -label "GotoMatingPool" -ann "Put cuurent gene into Mating Pool."
-command "gotoMatingPool($geneCodedString);";
setParent ..;
setParent ..;
frameLayout -label "Crossover Operation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Choose Parents" -ann "Choosing Parents in Mating Pool." -command
"chooseParentinPool($poolGathering);";
button -label "1 One-Point Crossover" -ann "One-Point Crossover Operation."
-command "onePcrossover($geneParent1,$geneParent2, $generation);";
button -label "2 Two-Point Crossover" -ann "two-Point Crossover Operation."
-command "twoPcrossover($geneParent1,$geneParent2, $generation);";
button -label "3 Three-Point Crossover" -ann "three-Point Crossover Operation."
-command "threePcrossover($geneParent1,$geneParent2, $generation);";
setParent ..;
setParent ..;
frameLayout -label "Mutation & Heuristic Operation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "single Mutation" -ann "Single-Point Mutation Operation." -command
"mutationGene($poolGathering, $generation);";
button -label "Multiple Mutation" -ann "Multiple-Point Mutation Operation."
-command "mutationGene1($poolGathering, $generation);";
button -label "Heuristic Search" -ann "Heuristic Operation." -command
"heuristicGene($poolGathering, $generation);";
setParent ..;
setParent ..;
frameLayout -label "Reproduction Operation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Reproduction" -ann "Reproducting the Fitness Offspring." -command
"reproductionGene($poolGathering, $generation);";
setParent ..;
setParent ..;
frameLayout -label "Next Generation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
button -label "Next Generation" -ann "Go to the Next generation." -command
"nextGeneration($generation, $kk);";
setParent ..;
setParent ..;
frameLayout -label "Control former Generation" -labelAlign "bottom" -borderStyle "etchedIn";
columnLayout -columnAttach "both" 12 -rowSpacing 8 -columnWidth 170;
-tabLabel $tab1 "Initilizeing"
-tabLabel $tab2 "Genetic Operations"
$tabs;
showWindow;
// 1. Selecting Stage
global proc selectObj(){
string $select[] = `ls -selection`;
global int $generation;
if(size($select)>1){
string $testSelect = `confirmDialog -message "Do you want to set these two objects as the parent?"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel" -dismissString "Cancel"`;
if($testSelect == "OK"){
duplicate -name selectCube1;
string $name1 = $select[0] + ".visibility";
string $name2 = $select[1] + ".visibility";
setAttr $name1 0;
setAttr $name2 0;
select -cl ; }
$generation = $generation + 1;
string $resetGindexeneration = "The current Generation is " +
$generation + " !!" +"\n";
global string $generationIform;
$generationIform = "generation " + $generation;
print $resetGindexeneration;
}else{
string $disselect= `confirmDialog -message "Warning: You didn't choose the enough objects!!" -button "OK" -defaultButton "OK" -dismissString
"Cancel"`;
if($disselect == "OK" || $disselect == "cancel") select -cl;
} }
global proc generateGene(string $name){
string $name1 = $name + 1;
string $name2 = $name + 2;
float $transCube1[] = `xform -q -t $name1`;
float $scaleCube1[] = `xform -q -r -s $name1`;
float $transCube2[] = `xform -q -t $name2`;
float $scaleCube2[] = `xform -q -r -s $name2`;
global float $gtransCube1[];
global float $gscaleCube1[];
global float $gtransCube2[];
global float $gscaleCube2[];
for ($i = 0; $i<size($transCube1); $i++)
$gtransCube1[$i] = $transCube1[$i];
for ($j = 0; $j<size($scaleCube1); $j++)
$gscaleCube1[$j] = $scaleCube1[$j];
for ($i = 0; $i<size($transCube1); $i++)
$gtransCube2[$i] = $transCube2[$i];
for ($j = 0; $j<size($scaleCube1); $j++)
$gscaleCube2[$j] = $scaleCube2[$j];
//chromosome grid X 座標
*******************************************************
float $chromx1 = $gtransCube1[0] - ($gscaleCube1[0] / 2);
float $chromx2 = $gtransCube1[0] + ($gscaleCube1[0] / 2);
float $chromx3 = $gtransCube2[0] - ($gscaleCube2[0] / 2);
float $chromx4 = $gtransCube2[0] + ($gscaleCube2[0] / 2);
float $chromX[] = { $chromx1, $chromx2, $chromx3, $chromx4 };
float $cXafterSort[] = sort($chromX);
//*********************
//chromosome grid Y 座標
float $chromy1 = $gtransCube1[1] - ($gscaleCube1[1]/ 2);
float $chromy2 = $gtransCube1[1] + ($gscaleCube1[1]/ 2);
float $chromy3 = $gtransCube2[1] - ($gscaleCube2[1]/ 2);
float $chromy4 = $gtransCube2[1] + ($gscaleCube2[1]/ 2);
float $chromY[] = { $chromy1, $chromy2, $chromy3, $chromy4 };
float $cYafterSort[] = sort($chromY);
//*********************
//chromosome grid Z 座標
float $chromz1 = $gtransCube1[2] - ($gscaleCube1[2] / 2);
float $chromz2 = $gtransCube1[2] + ($gscaleCube1[2] / 2);
float $chromz3 = $gtransCube2[2] - ($gscaleCube2[2] / 2);
float $chromz4 = $gtransCube2[2] + ($gscaleCube2[2] / 2);
float $chromZ[] = { $chromz1, $chromz2, $chromz3, $chromz4 };
float $cZafterSort[] = sort($chromZ);
//產生 Chromosome 的中心座標與邊長
***********************************************
//Chromosome X 中心座標
*********************************************************
float $Px0 = ($cXafterSort[0] + $cXafterSort[1])/2 ; float $Px1 = ($cXafterSort[1] + $cXafterSort[2])/2 ; float $Px2 = ($cXafterSort[2] + $cXafterSort[3])/2 ; //chromosome X 的邊長
float $Dx0 = $cXafterSort[1] - $cXafterSort[0] ; float $Dx1 = $cXafterSort[2] - $cXafterSort[1] ; float $Dx2 = $cXafterSort[3] - $cXafterSort[2] ; //Chromosome Y 中心座標
float $Py0 = ($cYafterSort[0] + $cYafterSort[1])/2 ; float $Py1 = ($cYafterSort[1] + $cYafterSort[2])/2 ; float $Py2 = ($cYafterSort[2] + $cYafterSort[3])/2 ; //chromosome Y 的邊長
float $Dy0 = $cYafterSort[1] - $cYafterSort[0] ; float $Dy1 = $cYafterSort[2] - $cYafterSort[1] ; float $Dy2 = $cYafterSort[3] - $cYafterSort[2] ; //Chromosome Z 中心座標
float $Pz0 = ($cZafterSort[0] + $cZafterSort[1])/2 ; float $Pz1 = ($cZafterSort[1] + $cZafterSort[2])/2 ; float $Pz2 = ($cZafterSort[2] + $cZafterSort[3])/2 ; //chromosome Z 的邊長
float $Dz0 = $cZafterSort[1] - $cZafterSort[0] ; float $Dz1 = $cZafterSort[2] - $cZafterSort[1] ; float $Dz2 = $cZafterSort[3] - $cZafterSort[2] ; global float $coordX[2];
float $Pxarray[] = {$Px0, $Px1, $Px2};
float $Pyarray[] = {$Py0, $Py1, $Py2};
float $Pzarray[] = {$Pz0, $Pz1, $Pz2};
float $Dxarray[] = {$Dx0, $Dx1, $Dx2};
float $Dyarray[] = {$Dy0, $Dy1, $Dy2};
float $Dzarray[] = {$Dz0, $Dz1, $Dz2};
$NumberX = size($Pxarray);
for ( $k = 0; $k < $NumberY; $k++){
string $used1 = $used[0] + ".visibility";
string $used2 = $used[1] + ".visibility";
setAttr $used1 0;
setAttr $used2 0;
//設其他的材質為透明
setAttr "lambert1.color" -type double3 0.739029 0.707506 0.95868;
setAttr "lambert1.transparency" -type double3 0.9 0.9 0.9 ; global int $generation;
int $indexg = ($generation-1)*27;
for($kk=$indexg; $kk<$indexg+27; $kk++){
int $kki = $kk-($generation-1)*27;
string $chromoname;
$chromoname = "chromo" + $kk;
float $px = $cube[$kki][0] ;
setAttr ($chromoname +".scaleX") $dx;
setAttr ($chromoname +".scaleY") $dy;
setAttr ($chromoname +".scaleZ") $dz;
move -r $px $py $pz ; }
select -cl;
}
global proc propagate(int $rG){
setAttr "lambert1.color" -type double3 0.739029 0.707506 0.95868;
setAttr "lambert1.transparency" -type double3 0.4 0.4 0.4 ; int $indexg = ($rG-1)*27;
int $rkk;
for($rkk=$indexg ; $rkk<$indexg+27; $rkk++){
string $chromoname;
// 2. Initializing Stage
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
if ($result == "OK") {
$text = `promptDialog -query -text`;
//print $text;
global string $populationSize;
$populationSize = $text;
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
if ($result == "OK") {
$text = `promptDialog -query -text`;
//print $text;
global string $complexValue;
$complexValue = $text;
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
proc string generGeneCode(int $fComplex, int $geneSize, int $nGeneration){
global int $chromo[];
global int $chromoselected[];
global int $finalSelectedIndex;
//int $chromo[];
//int $chromoselected[];
//int $finalSelectedIndex;
int $weight[];
int $weightRang[];
int $weightSum[];
int $ncol;
int $nrow;
for($ncol=0 ; $ncol<$geneSize ; $ncol++){
for ($nrow =0 ; $nrow<27; $nrow++){
$index = $ncol*27 + $nrow;
$chromo[$index]= 0;
} }
for($ncol=0 ; $ncol<$geneSize ; $ncol++){
for ($nrow =0 ; $nrow<$fComplex; $nrow++){
$i = `rand 27`;
clear $weightRang;
for($ncol=0 ; $ncol<$geneSize ; $ncol++){
for ($nrow =0 ; $nrow<27; $nrow++){
for($ncol=0 ; $ncol<$geneSize ; $ncol++){
for ($nrow =0 ; $nrow<27; $nrow++){
$weightSumSort = `sort $weightSum`;
global int $weightSSmax;
$weightSSmax = size($weightSumSort)-1;
for ($i=0 ; $i<size($weightSum) ; $i++){
if ($weightSumSort[$weightSSmax] == $weightSum[$i]){
$finalSelectedIndex = $i;
} }
for ($nrow =0 ; $nrow<27; $nrow++){
int $index = $finalSelectedIndex*27 + $nrow;
$chromoselected[$nrow] = $chromo[$index];
}
for ($nrow =0 ; $nrow<27; $nrow++){
int $index = $finalSelectedIndex*27 + $nrow;
$chromoselected[$nrow] = $chromo[$index];
}
for ($i=0 ; $i<size($weightSum) ; $i++){
if ($weightSumSort[$weightSSmax] == $weightSum[$i]){
for ($j=0; $j<27; $j++){
$index = $i*27 + $j;
$indexG = $j+($nGeneration-1)*27;
string $chromoname = "chromo" + $indexG;
string $name = $chromoname + ".visibility" ; if ( $chromo[$index] == 1 ){
string $abc = $chromoselected[$i];
$abcde = $abcde + $abc;
}
string $outputStringIndex;
if($finalSelectedIndex>9){
$outputStringIndex = $finalSelectedIndex;
}else{
$outputStringIndex = "0" + $finalSelectedIndex;
}
$weightR = `sort $weight`;
global int $geneFitSum ; $geneFitSum = 0;
global int $fitPercent;
for($i=0;$i<($fComplex+1);$i++){
int $j = 26;
$geneFitSum = $geneFitSum + $weightR[26-$i];
}
$fitPercent = `trunc ($weightSumSort[$weightSSmax]*100/$geneFitSum)`;
global string $geneCodedString;
string $abcdef = "IndexNum:" + $outputStringIndex +"_"+ "Weight:"+
$fitPercent + "%"+ $abcde + " ";
$geneCodedString = $abcdef;
print $geneCodedString;
print ("\n");
return $abcde;
}
//getMatingPool
global proc gotoMatingPool(string $choosedCode){
string $addGeneration = `confirmDialog -message "Do you want to put this population into Mating Pool" -button "OK"
-button "Cancel" -defaultButton "OK" -cancelButton
"Cancel"
-dismissString "Cancel"`;
global string $poolGathering;
if($addGeneration == "OK"){
$poolGathering = $poolGathering + $choosedCode;
int $sizeMP = (`size ($poolGathering)`)/50;
print ("The Number of Parent in Mating Pool = " + $sizeMP);
print ("\n");
for ($i=0; $i<(size($poolGathering)/50);$i++){
string $printone = `substring $poolGathering (1+$i*50) (50+$i*50)`;
print $printone;
print ("\n");
} }else{
confirmDialog -message "You just cancel this assignment" -button
"OK"
-defaultButton "OK";
} }
// 3. Propagating Stage
global proc chooseParentinPool(string $pgString){
//string $pgString;
//IndexNum:33_Weight:83%111011111001100100101010010 global string $mpool[];
global string $mpoolweiString[]; //string array global int $mpoolweiValue[]; //int array for ($i=0; $i<(size($pgString)/50);$i++){
$mpool[$i] = `substring $pgString (23+$i*50) (49+$i*50)`;
$mpoolweiString[$i] = `substring $pgString (20+$i*50) (21+$i*50)`;
print $mpool[$i];
print ("\n");
print $mpoolweiString[$i];
print ("\n");
string $stringTOintA;
string $stringTOintB;
$stringTOintA = `substring $mpoolweiString[$i] 1 1`;
$stringTOintB = `substring $mpoolweiString[$i] 2 2`;
int $digit10th;
int $digit1th;
if ($stringTOintA == "1"){
$digit10th = 10 ;
}else if($stringTOintA == "2"){
$digit10th = 20 ;
}else if($stringTOintA == "3"){
$digit10th = 30 ;
}else if($stringTOintA == "4"){
$digit10th = 40 ;
}else if($stringTOintA == "5"){
$digit10th = 50 ;
}else if($stringTOintA == "6"){
$digit10th = 60 ;
}else if($stringTOintA == "7"){
$digit10th = 70 ;
}else if($stringTOintA == "8"){
$digit10th = 80 ;
}else if($stringTOintA == "9"){
$digit10th = 90 ;
}else if($stringTOintB == "2"){
$digit1th = 2 ;
}else if($stringTOintB == "3"){
$digit1th = 3 ;
}else if($stringTOintB == "4"){
$digit1th = 4 ;
}else if($stringTOintB == "5"){
$digit1th = 5 ;
}else if($stringTOintB == "6"){
$digit1th = 6 ;
}else if($stringTOintB == "7"){
$digit1th = 7 ;
}else if($stringTOintB == "8"){
$digit1th = 8 ;
}else if($stringTOintB == "9"){
$digit1th = 9 ;
}else{
$digit1th = 0 ;
}
$mpoolweiValue[$i] = $digit10th + $digit1th;
print $mpoolweiValue[$i]; // string array print ("\n");
}
global int $mpoolweiValueS[];
$mpoolweiValueS = `sort $mpoolweiValue`;
int $indexMPmax1 = size($mpoolweiValueS)-1;
int $indexMPmax2 = size($mpoolweiValueS)-2;
global int $geneParentIndex1;
global int $geneParentIndex2;
global string $geneParent1;
global string $geneParent2;
for ($n= 0; $n<size($mpoolweiValue); $n++){
if ($mpoolweiValueS[$indexMPmax1] == $mpoolweiValue[$n]){
$geneParentIndex1 = $n;
$geneParent1 = $mpool[$n];
if ($n==(size($mpoolweiValue)-1)){
$geneParentIndex2 = $n-1;
$geneParent2 = $mpool[$geneParentIndex2];
}else if($n == 0){
$geneParentIndex2 = $n+1;
$geneParent2 = $mpool[$geneParentIndex2];
}else{
$geneParentIndex2 = $n-1;
$geneParent2 = $mpool[$geneParentIndex2];
} } }
global proc string onePcrossover(string $parent1, string $parent2, int
$nGeneration){
int $onePIndex1 = trunc (`rand 2 26`);
print ($onePIndex1+"\n");
string $new1Pchild = `substring $parent1 1 $onePIndex1` + `substring
$parent2 ($onePIndex1+1) 27`;
string $new1PchildCon[];
for ($i=1; $i<28; $i++){
$new1PchildCon[$i] = `substring $new1Pchild $i $i`;
}
for ($j=0; $j<27; $j++){
int $indexG;
$indexG = $j+($nGeneration-1)*27;
string $chromoname = "chromo" + $indexG;
string $name = $chromoname + ".visibility" ; if ( $new1PchildCon[$j] == "1" ){
print ("Index :" + $onePIndex1 + "\n"
+$parent1+"\n"+$parent2+"\n"+"new :"+"\n"+$new1Pchild+"\n");
print ("\n");
return $new1Pchild;
}
global proc string twoPcrossover(string $parent1, string $parent2, int
$nGeneration){
int $twoPIndex1 = trunc (`rand 3 26`);
int $twoPIndex2;
if($twoPIndex1 > 13){
$twoPIndex2 = trunc (`rand 1 $twoPIndex1`);
}else{
$twoPIndex2 = trunc (`rand ($twoPIndex1+2) 26`);
}
int $pIndex[]= {$twoPIndex1, $twoPIndex2};
$pIndex = `sort $pIndex`;
int $pDifference1 = $pIndex[1] - $pIndex[0];
int $pDifference2 = 26 - $pIndex[1];
int $twoPindex1Len = trunc (`rand 1 $pDifference1`);
int $twoPindex2Len = trunc (`rand 1 $pDifference2`);
int $twoPindex[];
$twoPindex[0] = $pIndex[0];
$twoPindex[1] = $pIndex[0]+$twoPindex1Len;
$twoPindex[2] = $pIndex[1];
$twoPindex[3] = $pIndex[1]+$twoPindex2Len;
$new2Pchild = `substring $parent1 1 $twoPindex[0]` + `substring $parent2 ($twoPindex[0]+1) $twoPindex[1]`+
`substring $parent1 ($twoPindex[1]+1)
$twoPindex[2]` + `substring $parent2 ($twoPindex[2]+1) $twoPindex[3]`+
`substring $parent1 ($twoPindex[3]+1) 27`;
string $new2PchildCon[];
for ($i=1; $i<28; $i++){
$new2PchildCon[$i] = `substring $new2Pchild $i $i`;
}
for ($j=0; $j<27; $j++){
int $indexG;
$indexG = $j+($nGeneration-1)*27;
string $chromoname = "chromo" + $indexG;
string $name = $chromoname + ".visibility" ; if ( $new2PchildCon[$j] == "1" ){
print ("Index_1 :" + $twoPindex[0] + "\n" + "Length_1 :" +
$twoPindex1Len + "\n" +
"Index_2 :" + $twoPindex[2] + "\n" + "Length_2 :" +
$twoPindex2Len + "\n" + $new2Pchild + "\n");
print ("Parent :" + "\n" + $parent1 + "\n" + $parent2 + "\n" );
print ("\n");
return $new2Pchild;
}
global proc string threePcrossover(string $parent1, string $parent2, int
$nGeneration){
int $threePIndex1 = trunc (`rand 4 26`);
int $threePIndex2;
int $threePIndex3;
if($threePIndex1 > 18){
$threePIndex2 = trunc (`rand 1 ($threePIndex1-1)`);
if($threePIndex2 > ($threePIndex1/2)){
$threePIndex3 = trunc (`rand 1 ($threePIndex2-1)`);
}else{
$threePIndex3 = trunc (`rand ($threePIndex2+2) ($threePIndex1-1)`);
}
}else if(9 < $threePIndex1 < 18){
$threePIndex2 = trunc (`rand 2 ($threePIndex1-1)`);
$threePIndex3 = trunc (`rand ($threePIndex1+2) 26`);
}else{
$threePIndex2 = trunc (`rand ($threePIndex1+2) 26`);
if($threePIndex2 > (($threePIndex1+27)/2)){
$threePIndex3 = trunc (`rand ($threePIndex1+2) ($threePIndex2-1)`);
}else{
$threePIndex3 = trunc (`rand ($threePIndex2+2) 26`);
} }
int $pIndex3[]= {$threePIndex1, $threePIndex2, $threePIndex3};
$pIndex3 = `sort $pIndex3`;
int $p3Difference1 = $pIndex3[1] - $pIndex3[0];
int $p3Difference2 = $pIndex3[2] - $pIndex3[1];
int $p3Difference3 = 26 - $pIndex3[2];
int $threePindex1Len = trunc (`rand 1 $p3Difference1`);
int $threePindex2Len = trunc (`rand 1 $p3Difference2`);
int $threePindex3Len = trunc (`rand 1 $p3Difference3`);
int $threePindex[];
//print $threePindex;
$new3Pchild = `substring $parent1 1 $threePindex[0]` + `substring $parent2 ($threePindex[0]+1) $threePindex[1]`+
`substring $parent1 ($threePindex[1]+1)
$threePindex[2]` + `substring $parent2 ($threePindex[2]+1) $threePindex[3]`+
`substring $parent1 ($threePindex[3]+1)
$threePindex[4]` + `substring $parent2 ($threePindex[4]+1) $threePindex[5]`+
`substring $parent1 ($threePindex[5]+1) 27`;
string $new3PchildCon[];
for ($i=1; $i<28; $i++){
$new3PchildCon[$i] = `substring $new3Pchild $i $i`;
}
for ($j=0; $j<27; $j++){
int $indexG;
$indexG = $j+($nGeneration-1)*27;
string $chromoname = "chromo" + $indexG;
string $name = $chromoname + ".visibility" ; if ( $new3PchildCon[$j] == "1" ){
setAttr $name 1;
}else{
setAttr $name 0;
}
}
print ("Index_1 :" + $threePindex[0] + "\n" + "Length_1 :" +
$threePindex1Len + "\n" +
"Index_2 :" + $threePindex[2] + "\n" + "Length_2 :" +
$threePindex2Len + "\n" +
"Index_3 :" + $threePindex[4] + "\n" + "Length_3 :" +
$threePindex3Len + "\n" + $new3Pchild + "\n");
print ("Parent :" + "\n" + $parent1 + "\n" + $parent2 + "\n" );
print ("\n");
return $new3Pchild;
}
global proc mutationGene(string $pgString, int $nGeneration){
global string $mpool[];
global string $mpoolweiString[]; //string array global int $mpoolweiValue[]; //int array for ($i=0; $i<(size($pgString)/50);$i++){
$mpool[$i] = `substring $pgString (23+$i*50) (49+$i*50)`;
$mpoolweiString[$i] = `substring $pgString (20+$i*50) (21+$i*50)`;
string $stringTOintA;
string $stringTOintB;
$stringTOintA = `substring $mpoolweiString[$i] 1 1`;
$stringTOintB = `substring $mpoolweiString[$i] 2 2`;
int $digit10th;
int $digit1th;
e[$i] = $digit10th + $digit1th;
}
global int $mpoolweiValueS[];
$mpoolweiValueS = `sort $mpoolweiValue`;
string $mutationString;
string $mutationArray[];
int $idexMmax = size($mpoolweiValueS)-1;
for ($i=0;$i<size($mpoolweiValue);$i++){
if($mpoolweiValueS[$idexMmax] == $mpoolweiValue[$i]){
$mutationString = $mpool[$i];
} }
for ($i=1; $i<(size($mutationString)+1);$i++){
$mutationArray[$i] = `substring $mutationString $i $i`;
}
int $indexMdigit = trunc(`rand 1 27`);
print ("Mutation Location : "+$indexMdigit+"\n");
if($mutationArray[$indexMdigit] == "0"){
$mutationArray[$indexMdigit] = "1";
}else{
$mutationArray[$indexMdigit] = "0";
}
string $name = $chromoname + ".visibility" ; if ( $mutationArray[$j] == "1" ){
global proc mutationGene1(string $pgString, int $nGeneration){
global string $mpool[];
global string $mpoolweiString[]; //string array global int $mpoolweiValue[]; //int array for ($i=0; $i<(size($pgString)/50);$i++){
$mpool[$i] = `substring $pgString (23+$i*50) (49+$i*50)`;
$mpoolweiString[$i] = `substring $pgString (20+$i*50) (21+$i*50)`;
string $stringTOintA;
string $stringTOintB;
$stringTOintA = `substring $mpoolweiString[$i] 1 1`;
$stringTOintB = `substring $mpoolweiString[$i] 2 2`;
int $digit10th;
int $digit1th;
if ($stringTOintA == "1"){
$digit10th = 10 ;
}else if($stringTOintA == "2"){
$digit10th = 20 ;
}else if($stringTOintA == "3"){
$digit10th = 30 ;
}else if($stringTOintA == "4"){
$digit10th = 40 ;
}else if($stringTOintA == "5"){
$digit10th = 50 ;
}else if($stringTOintA == "6"){
$digit10th = 60 ;
}else if($stringTOintA == "7"){
$digit10th = 70 ;
}else if($stringTOintA == "8"){
$digit10th = 80 ;
}else if($stringTOintA == "9"){
$digit10th = 90 ;
}else if($stringTOintB == "2"){
$digit1th = 2 ;
}else if($stringTOintB == "3"){
$digit1th = 3 ;
}else if($stringTOintB == "4"){
$digit1th = 4 ;
}else if($stringTOintB == "5"){
$digit1th = 5 ;
}else if($stringTOintB == "6"){
$digit1th = 6 ;
}else if($stringTOintB == "7"){
$digit1th = 7 ;
}else if($stringTOintB == "8"){
$digit1th = 8 ;
}else if($stringTOintB == "9"){
$digit1th = 9 ;
}else{
$digit1th = 0 ;
}
$mpoolweiValue[$i] = $digit10th + $digit1th;
}
global int $mpoolweiValueS[];
$mpoolweiValueS = `sort $mpoolweiValue`;
string $mutationString;
string $mutationArray[];
int $indexM;
int $mpsize = size($mpool);
$indexM = trunc(`rand 1 $mpsize`);
$mutationString = $mpool[$indexM];
for ($i=1; $i<(size($mutationString)+1);$i++){
$mutationArray[$i] = `substring $mutationString $i $i`;
}
int $indexMdigit = trunc(`rand 1 27`);
print ("Mutation Location : "+$indexMdigit+"\n");
if($mutationArray[$indexMdigit] == "0"){
$mutationArray[$indexMdigit] = "1";
}else{
$mutationArray[$indexMdigit] = "0";
}
string $name = $chromoname + ".visibility" ; if ( $mutationArray[$j] == "1" ){
}
global proc heuristicGene(string $pgString, int $nGeneration){
string $mpool[];
for ($i=0; $i<(size($pgString)/50);$i++){
$mpool[$i] = `substring $pgString (23+$i*50) (49+$i*50)`;
}
int $heuristicValue;
int $hv1;
int $hv2;
string $hvString1;
string $hvString2;
string $hvString1p[];
string $hvString2p[];
string $heuristicString;
string $heuristicArray[];
int $p1;
int $p2;
$p1 = trunc (`rand 1 90`);
$p2 = 100-$p1;
int $mpSize = size($mpool);
int $idexHrand1 = trunc (`rand 1 $mpSize`);
int $idexHrand2 = trunc (`rand 1 $mpSize`);
$hvString1 = $mpool[$idexHrand1];
$hvString2 = $mpool[$idexHrand2];
for ($i=0; $i<size($hvString1);$i++){
$hvString1p[$i] = `substring $hvString1 ($i+1) ($i+1)`;
}
for ($i=0; $i<size($hvString2);$i++){
$hvString2p[$i] = `substring $hvString2 ($i+1) ($i+1)`;
}
print ("Heuristic Value 1 = ");
int $iHcaculate;
global int $hv1;
for ($iHcaculate = 0; $iHcaculate<size($hvString1p) ; $iHcaculate++){
if ($hvString1p[$iHcaculate] == 0){
int $powH1 =0;
$hv1 = $hv1 + 0;
print ($powH1);
}else{
int $powH2 = `pow 2 (26-$iHcaculate)`;
$hv1 = $hv1 + $powH2;
print ("Heuristic Value 2 = ");
global int $hv2;
for ($iHcaculate = 0; $iHcaculate<(size($hvString2p)) ; $iHcaculate++){
if ($hvString2p[$iHcaculate] == 0){
int $powH1 =0;
$hv2 = $hv2 + 0;
print ($powH1);
}else{
int $powH2 = `pow 2 (26-$iHcaculate)`;
$hv2 = $hv2 + $powH2;
$heuristicValue = trunc ($hv1/100*$p1 + $hv2/100*$p2);
print (" The Value of Heuristic Gene ==> " + "\n" + " A " + $hv1 + " X " +
$p1 + " %"+"\n" +
"+ B " + $hv2 + " X " + $p2 +" %" + "\n" + "= H "
+$heuristicValue + "\n");
int $caculateH = $heuristicValue;
for ($iHs = 0; $iHs < size($hvString1p) ; $iHs++){
int $powCompare = `pow 2 (27-$iHs)`;
if ($caculateH > $powCompare ){
$heuristicString = $heuristicString + 1;
$caculateH = $caculateH - $powCompare;
}else{
$heuristicString = $heuristicString + 0;
} }
print ("The string code of this heuristic operation =" + $heuristicString + ";"
+"\n");
for ($i=0; $i<size($heuristicString);$i++){
$heuristicArray[$i] = `substring $heuristicString ($i+1) ($i+1)`;
}
string $chromoname = "chromo" + $indexG;
string $name = $chromoname + ".visibility" ; if ( $heuristicArray[$j] == "1" ){
global proc string m1RGene(string $pgString, int $nGeneration){
global string $mpool[];
global string $mpoolweiString[]; //string array global int $mpoolweiValue[]; //int array for ($i=0; $i<(size($pgString)/50);$i++){
$mpool[$i] = `substring $pgString (23+$i*50) (49+$i*50)`;
$mpoolweiString[$i] = `substring $pgString (20+$i*50) (21+$i*50)`;
string $stringTOintA;
string $stringTOintB;
$stringTOintA = `substring $mpoolweiString[$i] 1 1`;
$stringTOintB = `substring $mpoolweiString[$i] 2 2`;
int $digit10th;
int $digit1th;
if ($stringTOintA == "1"){
$digit10th = 10 ;
}else if($stringTOintA == "2"){
$digit10th = 20 ;
}else if($stringTOintA == "3"){
$digit10th = 30 ;
}else if($stringTOintA == "4"){
$digit10th = 40 ;
}else if($stringTOintA == "5"){
$digit10th = 50 ;
}else if($stringTOintA == "6"){
$digit10th = 60 ;
}else if($stringTOintA == "7"){
$digit10th = 70 ;
}else if($stringTOintA == "8"){
$digit10th = 80 ;
}else if($stringTOintA == "9"){
$digit10th = 90 ;
}else{
$digit10th = 0 ;
}
if ($stringTOintB == "1"){
$digit1th = 1 ;
}else if($stringTOintB == "2"){
$digit1th = 2 ;
}else if($stringTOintB == "3"){
$digit1th = 3 ;
}else if($stringTOintB == "4"){
$digit1th = 4 ;
}else if($stringTOintB == "5"){
$digit1th = 5 ;
}else if($stringTOintB == "6"){
$digit1th = 6 ;
}else if($stringTOintB == "7"){
$digit1th = 7 ;
}else if($stringTOintB == "8"){
$digit1th = 8 ;
}else if($stringTOintB == "9"){
$digit1th = 9 ;
}else{
$digit1th = 0 ;
}
$mpoolweiValue[$i] = $digit10th + $digit1th;
}
global int $mpoolweiValueS[];
$mpoolweiValueS = `sort $mpoolweiValue`;
string $reproductionString;
string $reproductionArray[];
int $idexRmax = size($mpoolweiValueS)-1;
for ($i=0;$i<size($mpoolweiValue);$i++){
if($mpoolweiValueS[$idexRmax] == $mpoolweiValue[$i]){
$reproductionString = $mpool[$i];
} }
return $reproductionString;
}
// 4. Terminating Stage
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
if ($result == "OK") {
$text = `promptDialog -query -text`;
int $index = `size $text`;
global int $geneResetIndex[];
clear $geneResetIndex;
for($i=0; $i<$index; $i++){
$geneResetIndex[$i] = `substring $text ($index-$i) ($index-$i)`;
}else if ($geneResetIndex[$i] == "1"){
$s2i[$i] = 1;
global proc controlResetG(int $num){
int $indexg = ($num-1)*27;
for($rkk= $indexg; $rkk<$indexg+27; $rkk++){
string $chromoname ;