Example #1
0
bool Repository::r_idealArchiver(Solution &candidate){
	insert(candidate);
	organize();
	
	double highDistanceValue=MAXDOUBLE*-1;
	int higherIndex=-1;
	
	for(int i=0;i<actualSize;i++){
		double norm[objectiveNumber];
		double dist=0;
		normalizeObjectives(norm, solutions[i].objectiveVector);

		dist=calculateEuclideanDistance(norm, weight, objectiveNumber);
		if(dist > highDistanceValue){
			highDistanceValue=dist;
			higherIndex=i;
		}
	}
	if(higherIndex==-1){
		fprintf(stderr,"\nR-IDEAL ARCHIVER ERROR %f\n", highDistanceValue);
		exit(1);
	}
	bool ret=true;
	if(candidate.isEqual(solutions[higherIndex]))
		ret=false;
	
	exclude(higherIndex);
	
	return ret;
}
Example #2
0
//archiver proposed by Laumanns and Zenklusken
//param - the solution to be submitted to the archiver
bool Repository::MGAArchiver(Solution &candidate){
	insert(candidate);
	organize();
	int b = compute_b_mga(solutions, actualSize);
	int index_removed = -1;
	while(index_removed==-1){
		for(int i = actualSize-1; i>=0;i--){
			double box_i[objectiveNumber];
			box_mga(solutions[i], box_i, b, objectiveNumber);
			for(int j = actualSize-1; j>=0;j--){
				if(i!=j){
					double box_j[objectiveNumber];
					box_mga(solutions[j], box_j, b, objectiveNumber);
					int comparation = dominance(box_i, box_j, objectiveNumber);
					if(comparation == -1 || isEqual(box_i, box_j, objectiveNumber) ){
						index_removed = i;
						break;
					}
				}
			}
			//if(index_removed!=-1){
			//	break;
			//}
		}
		b--;
	}
	
	bool ret=true;
	if(candidate.isEqual(solutions[index_removed]))
		ret=false;
	
	exclude(index_removed);
	
	return ret;
}
Example #3
0
bool Repository::WSumArchiver(Solution &candidate){
	//http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7020200
	//double weight[]={0.1,0.9};
	insert(candidate);
	organize();
	
	double highDistanceValue=MAXDOUBLE*-1;
	int higherIndex=-1;
	
	for(int i=0;i<actualSize;i++){
		double norm[objectiveNumber];
		double wsum=0;
		normalizeObjectives(norm, solutions[i].objectiveVector);
		
		for(int j=0;j<objectiveNumber;j++){
			wsum+=(weight[j]*norm[j]);
		}
		if(wsum > highDistanceValue){
			highDistanceValue=wsum;
			higherIndex=i;
		}
	}
	if(higherIndex==-1){
		fprintf(stderr,"\nWSum ARCHIVER ERROR %f\n", highDistanceValue);
		exit(1);
	}
	bool ret=true;
	if(candidate.isEqual(solutions[higherIndex]))
		ret=false;
	
	exclude(higherIndex);
	
	return ret;
}
Example #4
0
//archiver proposed by Carvalho and Pozo //Removes the solutio with worst distance to the ideal point
//param - the solution to be submitted to the archiver
bool Repository::idealArchiver(Solution &candidate){
	insert(candidate);
	organize();
	
	double solNorm[objectiveNumber];
	double idealNorm[objectiveNumber];
	double higherDistance=-1;
	double distance=0;
	int index=-1;
	
	memset(idealNorm, 0, sizeof(double)*objectiveNumber); //since the points are normalized between 0 and 1, the ideal point will be (0,...,0)
		
	for(int i=0;i<actualSize;i++){
		normalizeObjectives(solNorm, solutions[i].objectiveVector);
		
		distance=calculateEuclideanDistance(solNorm, idealNorm, objectiveNumber);
		
		if(distance > higherDistance){
			higherDistance=distance;
			index=i;
		}
	}
	
	if(index==-1){
		fprintf(stderr,"\nIDEAL ARCHIVER ERROR %f\n", higherDistance);
		exit(1);
	}
	
	bool ret=true;
	if(candidate.isEqual(solutions[index]))
		ret=false;
	
	exclude(index);
	
	return ret;
	
// 	/*//For each solution on the front, it calculates the distance to the ideal point
// 	double smallerDistance[actualSize];
// 	
// 	for(int i=0;i<actualSize;i++){
// 		double norm[objectiveNumber];
// 		double sp_norm[objectiveNumber];
// 		for(int j=0;j<objectiveNumber;j++){
// 			norm[j]=normalize(solutions[i].objectiveVector[j],smallerObjs[j],largerObjs[j]);
// 			sp_norm[j]=normalize(smallerObjs[j],smallerObjs[j],largerObjs[j]);
// 		}
// 		smallerDistance[i] = calculateEuclideanDistance(sp_norm, norm, objectiveNumber);
// 		//smallerDistance[i] = calculateEuclideanDistance(smallerObjs, solutions[i].objectiveVector, objectiveNumber);
// 	}
// 
// 	double highDistanceValue = -1.0;
// 	int index = -1;
// 	for (int i = 0; i<actualSize; i++) {
// 		if(smallerDistance[i] > highDistanceValue){
// 			highDistanceValue =smallerDistance[i];
// 			index = i;
// 		}
// 	}*/
}
Example #5
0
//tries to add a solution in the repository if it is non-dominated
//param - the candidate solution to be inserted in the repository
 bool Repository::add(Solution &candidate){
	bool isDominated=false;
	bool equal=false;
	int dom;
	bool enteredArchive=false;
	if(actualSize==0){ //if the repository is empty, insert the solution
		insert(candidate);
		enteredArchive=true;
	}else{
		for(int s=0;s<repositorySize+1;s++){
			if(controlSolutions[s]){//if this solution is valid
				if(!candidate.isEqual(getSolution(s))){ //if the solutions are not equal
					//verify the dominance relation between two vectors
					//return 1 if sol1 dominates sol2, -1 if sol2 dominates sol1, 0 if they do not dominate each other, 2 if they are equal
					if(!strcmp(archiverType, "pbi") || !strcmp(archiverType, "tch")  || !strcmp(archiverType, "wcp") || !strcmp(archiverType, "wsum") || !strcmp(archiverType, "r-ideal"))//repositories based on decomposition, if decomposition do not check dominance
						dom=0;
					else
						dom=dominance(candidate.objectiveVector, getSolution(s).objectiveVector, objectiveNumber);

					if(dom == 1){//if the candidate dominates the solution in the repository
						exclude(s);
					}else{
						if(dom == -1){//if a solution in the repository dominates the candidate
							isDominated=true;
							if(vectorZero(getSolution(s).objectiveVector, objectiveNumber)){
								fprintf(stderr, "\nERROR! Trying to insert in the repository a solution whose objectives are all 0\n");
								exit(1);
							}
							break;
						}
					}
				}else{ //if the solutions are equal, discard the candidate
					equal=true;
					break;
				}
			}
		}

		if(!isDominated && !equal){ //if the solution is non-dominated
			candidate.dominated=false;
			if(actualSize<repositorySize){//if the repository is not empty nor full
				insert(candidate);//insert the solution
				enteredArchive=true;
			}else{ //if the repository is full
				enteredArchive=archiver(candidate);
			}
		}else{
			candidate.dominated=true;
			enteredArchive=false;
		}
	}
	return enteredArchive;
}
Example #6
0
//archiver wich consider the crowding distance to keep/exclude a solution
//param - the solution to be submitted to the archiver
bool Repository::crowdingDistanceArchiver(Solution &candidate){
	//Solution temp[repositorySize+1]; //create a temporary repository to contain all the solutions plus the candidate
	double smallerCrowdingDistance=MAXDOUBLE;
	int idxSmallerCrowdingDistance=-1;

	//sync(temp); //sincronize the new repository with the solutions already found
//	for(int i=0;i<actualSize;i++)
//		temp[i]=solutions[i];
	//memcpy(temp, solutions, sizeof(Solution)*actualSize);

	//solutions[actualSize]=candidate;//insert the new one
	insert(candidate);
		
	organize();
	updateCrowdingDistances(solutions, actualSize); //update the crowing distances

	for(int i=0;i<actualSize;i++){//find the valid solution with smallest crowding distance
		if(controlSolutions[i] && getSolution(i).crowdingDistance<=smallerCrowdingDistance){
			smallerCrowdingDistance=getSolution(i).crowdingDistance;
			idxSmallerCrowdingDistance=i;
		}
	}
	
	if(idxSmallerCrowdingDistance == -1){
		fprintf(stderr,"\nCrowding Distance archiver error!\n The crowding distances of all particles in the repository is:\n");
		for(int i=0;i<actualSize;i++)
			fprintf(stderr,"%f\n", getSolution(i).crowdingDistance);
		exit(1);
	}
	
	
//	if(!solutions[idxSmallerCrowdingDistance].isEqual(candidate)){ //if the candidate is not the solution with smallest crowding distance
	bool ret=true;
	if(candidate.isEqual(solutions[idxSmallerCrowdingDistance]))
		ret=false;
	
	exclude(idxSmallerCrowdingDistance); //remove the solution with the smallest crowding distance
	
	return ret;
	//insert(candidate);//insert the new solution
//	}

	//free(temp);
}
Example #7
0
bool Repository::pbiArchiver(Solution &candidate){
	//http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7020200
	//double weight[]={0.1,0.9};
	insert(candidate);
	organize();
	
	double highDistanceValue=MAXDOUBLE*-1;
	int higherIndex=-1;
	double solNorm[objectiveNumber];
// 	double *solNorm;
	
	for(int i=0;i<actualSize;i++){
		double norm;
		double pbi=0;
		normalizeObjectives(solNorm, solutions[i].objectiveVector);
// 		solNorm=solutions[i].objectiveVector;
		
		pbi=PBI(solNorm, weight);
		if(pbi > highDistanceValue){
			highDistanceValue=pbi;
			higherIndex=i;
		}
	}

	if(higherIndex==-1){
		fprintf(stderr,"\nPBI ARCHIVER ERROR %f %f\n", PBI(solNorm, weight), highDistanceValue);
		candidate.print();
		printf("\nweight: ");
		printVector(weight, objectiveNumber);
		printf("\n");
		exit(1);
	}
	
	bool ret=true;
	if(candidate.isEqual(solutions[higherIndex]))
		ret=false;
	
	exclude(higherIndex);
	
	return ret;
}
Example #8
0
//archiver wich consider the contributing HV to keep/exclude a solution
//param - the solution to be submitted to the archiver
bool Repository::HVArchiver(Solution &candidate){
	double smallestHV=MAXDOUBLE;
	int idxSmallestHV=-1;
	
	insert(candidate);
	
	for(int i=0;i<actualSize;i++)
		getSolutions()[i].crowdingDistance=-1;
	
	organize();
	updateContributingHypervolume(*this); //update the contributing HV of all solutions
	// 	updateContributingHypervolume(*this);
	
	
	for(int i=0;i<actualSize;i++){//find the valid solution with smallest contributing HV (stored on the crowding distance field)
		if(controlSolutions[i] && getSolution(i).crowdingDistance<=smallestHV){
			smallestHV=getSolution(i).crowdingDistance;
			idxSmallestHV=i;
		}
	}
	
	if(idxSmallestHV == -1){
		fprintf(stderr,"\nHV archiver error!\n The HV of all particles in the repository is:\n");
		for(int i=0;i<actualSize;i++)
			fprintf(stderr,"%f\n", getSolution(i).crowdingDistance);
		exit(1);
	}
	
	// 	fprintf(stderr,"%d --> %f  (%d)\n",idxSmallerR2, smallerR2, actualSize);
	// 	if(actualSize > repositorySize)//test of removing all solutions with no contribution
	
	bool ret=true;
	if(candidate.isEqual(solutions[idxSmallestHV]))
		ret=false;
	
	exclude(idxSmallestHV); //remove the solution with the smallest contribution
	
	return ret;
}
Example #9
0
bool Repository::tchArchiver(Solution &candidate){
	//http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7020200
	insert(candidate);
	organize();
	
	double highDistanceValue=MAXDOUBLE*-1;
	int higherIndex=-1;
	double solNorm[objectiveNumber];
// 	double *solNorm;
	
	for(int i=0;i<actualSize;i++){
		double norm;
		double tch=0;
		normalizeObjectives(solNorm, solutions[i].objectiveVector);
// 		solNorm=solutions[i].objectiveVector;
		
		tch=TCH(solNorm, weight);
		if(tch > highDistanceValue){
			highDistanceValue=tch;
			higherIndex=i;
		}
	}
	
	if(higherIndex==-1){
		fprintf(stderr,"\nTCH ARCHIVER ERROR %f\n", highDistanceValue);
		printVector(solNorm, objectiveNumber);
		fprintf(stderr,"\n");
		exit(1);
	}
	
	bool ret=true;
	if(candidate.isEqual(solutions[higherIndex]))
		ret=false;
	
	exclude(higherIndex);
	
	return ret;
}
Example #10
0
//add a solution ignoring whether the repository is full or not
void Repository::forceAdd(Solution &candidate){
	bool isDominated=false;
	bool equal=false;
	if(actualSize==0){ //if the repository is empty, insert the solution
		insert(candidate);
	}else{
		for(int s=0;s<repositorySize+1;s++){
			if(controlSolutions[s]){//if this solution is valid
				if(!candidate.isEqual(getSolutions()[s])){ //if the solutions are not equal
					//verify the dominance relation between two vectors
					//return 1 if sol1 dominates sol2, -1 if sol2 dominates sol1, 0 if they do not dominate each other, 2 if they are equal
					if(dominance(candidate.objectiveVector, getSolution(s).objectiveVector, objectiveNumber) == 1){//if the candidate dominates the solution in the repository
						exclude(s);
					}else{
						if(dominance(candidate.objectiveVector, getSolution(s).objectiveVector, objectiveNumber) == -1){//if a solution in the repository dominates the candidate
							isDominated=true;
							break;
						}
					}
				}else{ //if the solutions are equal, discard the candidate
					equal=true;
					break;
				}
			}
		}

		if(!isDominated && !equal){ //if the solution is non-dominated
			if(actualSize<repositorySize+1){//if there is memory left
				insert(candidate);//insert the solution
			}else{ //if there is not memory left
				fprintf(stderr,"REPOSITORY MEMORY UNAVAILABLE, INCREASE THE REPOSITORY MAXIMUM SIZE\n");
				//exit(1);
			}
		}
	}
}