Accueil > Forum > > > > j'ai besoin de vous!!!
j'ai besoin de vous!!!
samedi 18 juin 2011 à 12:07:17 |
j'ai besoin de vous!!!

baster200x
|
bonjour les amis
j'ai trouvé la solution pour mes problème que je l'ai poser précédemment sur le forum à propos de l'intégration d'un module d'optimisation (algorithme d'optimisation) VEGA dans un outil Open Source nommé Multicube explorer;
la solution consiste à créer la class .CPP + le fichier header .h de l'algorithme VEGA (ce qui est fait!) avant l'installation de l'outil; le problème qui ce pose c'est que pour le faire marcher, je ne sais pas ce qu'il doit prendre comme paramètre  .
m3explorer c'est un outil pour l'exploration des architecture paramétrable,
j'ai essayé de lire la documentation sur l'API de m3explorer et j'ai rien pigé.
voilà mon algorithme:
---------------------
main.cpp:
---------
Code C/C++ :
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
FILE *fichier, *cache, *temps_access, *puissance_access, *pop;
int main(int argc, char ** argv)
{
double ** T = new double* [50];
for(int i = 0; i < 50; ++i) T[i] = new double[nbTache];
double ** C = new double* [50];
for(int i = 0; i < 50; ++i) C[i] = new double[nbTache];
pop = fopen("pop.txt", "r");
fichier = fopen("resultat.txt", "r");
for (int i = 0; i < 50; i++)
for (int j = 0; j < nbTache; j++)
fscanf(fichier, "%lf%lf", &T[i][j], &C[i][j]);
fclose(fichier);
double * Taille = new double [50];
cache = fopen("cache.txt", "r");
for (int h = 0; h < 50; h++) fscanf(cache, "%lf", &Taille[h]);
fclose(cache);
double *Taccess = new double [50];
temps_access = fopen("temps_access.txt", "r");
for (int h = 0; h < 50; h++) fscanf(temps_access, "%lf", &Taccess[h]);
fclose(temps_access);
double * Paccess = new double [50];
puissance_access = fopen("puissance_access.txt", "r");
for (int h = 0; h < 50; h++) fscanf(puissance_access, "%lf", &Paccess[h]);
fclose(puissance_access);
double ** Tc = new double* [50];
for(int i = 0; i < 50; ++i) Tc[i] = new double[50];
for (int i = 0; i < 50; i++)
for (int j = 0; j < 50; j++)
{
if (i == j) Tc[i][j] = 0;
else if (Taille[i] < Taille[j]) Tc[i][j] = 0;
else Tc[i][j] = Taccess[i] * (Taille[i] - Taille[j]);
}
double ** Cc = new double* [50];
for(int i = 0; i < 50; ++i) Cc[i] = new double[50];
for (int i = 0; i < 50; i++)
for (int j = 0; j < 50; j++)
{
if (i == j) Cc[i][j] = 0;
else if (Taille[i] < Taille[j]) Cc[i][j] = 0;
else Cc[i][j] = Paccess[i] * (Taille[i] - Taille[j]);
}
int ** p = new int* [100];
for(int i = 0; i < 100; ++i) p[i] = new int[nbTache];
for (int i = 0; i < 50; i++)
for (int j = 0; j < 50; j++)
p[i][j] = rand();
// Evaluation des individus ou calcul de Fitness
double * Ft = new double [100];
double * Fc = new double [100];
int * par1 = new int [nbTache];
int * par2 = new int [nbTache];
int * enf1 = new int [nbTache];
int * enf2 = new int [nbTache];
int ** p1 = new int* [100];
for(int i = 0; i < 100; ++i) p1[i] = new int[nbTache];
int ** p2 = new int* [100];
for(int i = 0; i < 100; ++i) p2[i] = new int[nbTache];
int * In = new int [2];
// Evaluation des individus
f1(100, nbTache, p, T, Tc, Ft, p1);
f2(100, nbTache, p, C, Cc, Fc, p2);
selection(100, nbTache, p, Ft, Fc, par1, par2, In);
for (int i = 0; i < 100; i++)
{
printf("%d ", i);
for (int j = 0; j < nbTache; j++) printf("%d ", p[i][j]);
printf("\n");
}
f1(100, nbTache, p, T, Tc, Ft, p1);
f2(100, nbTache, p, C, Cc, Fc, p2);
// Sélection
int k = 0;
int l = 1;
while (k < 500)
{
//nombre de génération
// croisement
croisement(100, nbTache, p, par1, par2, enf1, enf2, In, T, Tc, C, Cc);
// Mutation
mutation(100, nbTache, p, T, Tc, C, Cc);
// pop après reclassement, croisement et mutation
selection(100, nbTache, p, Ft, Fc, par1, par2, In);
//c la j'ai ajoutée une condition qui teste si c la premiere itération alors
//imprimé ou si pair de 10 imprimer aussi car je veux avoir 1 10 20 30 40 50 60 70 80 90 100
if (l % 50 == 0)
{
printf("%d\n", l);
for (int i = 0; i < 100; i++)
{
printf( "%d ", i);
for (int j = 0; j < nbTache; j++)
{
printf("%d ", p[i][j]);
}
printf("\n");
}
f1(100, nbTache, p, T, Tc, Ft, p1);
f2(100, nbTache, p, C, Cc, Fc, p2);
}
k++;
l++;
}
fclose(pop);
}
main.h:
--------
Code C/C++ :
void f1(int lig, int col, int ** p, double ** t,double ** tc, double * f, int ** p1);
void f2(int lig, int col, int ** p, double ** c, double ** cc, double * f, int ** p2);
void selection(int lig, int col, int ** p, double * f1, double * f2, int * par1, int * par2, int * ind);
void croisement(int lig, int col, int ** p, int * par1, int * par2, int * enf1, int * enf2, int * ind, double ** t, double ** tc, double ** c, double ** cc);
void mutation(int lig, int col, int ** p, double ** t, double ** tc, double ** c, double ** cc);
double fti(int col, int * individu, double ** t, double ** tc);
double fci(int col, int * individu, double ** c, double ** cc);
int nbTache = 10;
FILE *tempsAg, *puisAg;
void f1(int lig, int col, int ** p, double ** t,double ** tc, double * f, int ** p1)
{
double s1, s2;
double * S1 = new double [lig];
double * S2 = new double [lig];
for (int i = 0; i < lig; i++)
{
s1 = 0;
for (int j = 0; j < col; j++)
s1 += t[p[i][j]][j];
S1[i] = s1;
}
for (int i = 0; i < lig; i++)
{
s2 = 0;
for (int j = 0; j < col-1; j++)
s2 += tc[p[i][j]][p[i][j + 1]];
S2[i] = s2;
}
tempsAg = fopen("tempsAg.txt", "w");
printf(" Ft\n");
for (int i = 0; i < lig; i++)
{
f[i] = S1[i] + S2[i];
fprintf(tempsAg, "%lf\n", f[i]);
}
fclose(tempsAg);
}
void f2(int lig, int col, int ** p, double ** c, double ** cc, double * f, int ** p2)
{
double s1, s2;
double * S1 = new double[lig];
double * S2 = new double[lig];
for (int i = 0; i < lig; i++)
{
s1 = 0;
for (int j = 0; j < col; j++) s1 += c[p[i][j]][j];
S1[i] = s1;
}
for (int i = 0; i < lig; i++)
{
s2 = 0;
for (int j = 0; j < col - 1; j++) s2 += cc[p[i][j]][p[i][j + 1]];
S2[i] = s2;
}
puisAg = fopen("puisAg.txt", "w");
printf("Fc\n");
for (int i = 0; i < lig; i++)
{
f[i] = S1[i] + S2[i];
fprintf(puisAg, "%lf\n", f[i]);
printf("%lf\n", f[i]);
}
fclose(puisAg);
}
// Appliquer l'algorithme VEGA pour la selection des individus qui feront
// objet d'un croisement et/ou Mutation
void selection(int lig, int col, int ** p, double * f1, double * f2, int * par1, int * par2, int * ind)
{
// Sous pop 1 les 50 premiers individus sont classés selon F1
double z;
int x;
//Classement selon F1
for (int i = 0; i < ( (lig / 2) - 1); i++)
{
for (int j = i + 1; j < lig / 2; j++)
{
if (f1[j] < f1[i])
{
z = f1[i];
f1[i] = f1[j];
f1[j] = z;
for (int h = 0; h < col; h++)
{
x = p[i][h];
p[i][h] = p[j][h];
p[j][h] = x;
}
}
}
}
double z1;
int x1; //classement selon F2
for (int i = (lig / 2); i < lig - 1; i++)
{
for (int j = i + 1; j < lig; j++)
{
if (f2[j] < f2[i])
{
z1 = f2[i];
f2[i] = f2[j];
f2[j] = z1;
for (int h = 0; h < col; h++)
{
x1 = p[i][h];
p[i][h] = p[j][h];
p[j][h] = x1;
}
}
}
}
ind[0] = rand() % 50;
ind[1] = rand() % 50;
for (int i = 0; i < lig; i++)
{
if (i == ind[0])
{
for (int j = 0; j < col; j++)
{
par1[j] = p[i][j];
}
}
}
for (int i = 0; i < lig; i++)
{
if (i == ind[1])
{
for (int j = 0; j < col; j++)
{
par2[j] = p[i][j];
}
}
}
}
void croisement(int lig, int col, int ** p, int * par1, int * par2, int * enf1, int * enf2, int * ind, double ** t, double ** tc, double ** c, double ** cc)
{
for (int j = 0; j < col / 2; j++)
{
enf1[j] = par1[j];
enf2[j] = par2[j];
}
for (int j = col / 2; j < col; j++)
{
enf1[j] = par2[j];
enf2[j] = par1[j];
}
if (fti(col, enf1, t, tc) < fti(col, par1, t, tc))
{
for (int j = 0; j < col; j++)
{
p[ind[0]][j] = enf1[j];
}
}
if (fci(col, enf2, c, cc) < fci(col, par2, c, cc))
{
for (int j = 0; j < nbTache; j++)
{
p[ind[1]][j] = enf2[j];
}
}
}
void mutation(int lig, int col, int ** p, double ** t, double ** tc, double ** c, double ** cc)
{
int * mut = new int[lig];
int * mut1 = new int[lig];
int id = rand() % 100;
for (int i = 0; i < lig; i++)
{
if (i == id)
{
for (int j = 0; j < col; j++)
{
mut[j] = p[i][j];
mut1[j] = mut[j];
}
}
}
int id1 = rand() % col;
for (int j = 0; j < col; j++)
{
if (j == id1)
{
mut1[j] = 49 - mut[j];
}
}
if ( (fti(col, mut1, t, tc) < fti(col, mut, t, tc)) && (fti(col, mut1, t, tc) < fti(col, mut, t, tc)))
{
for (int j = 0; j < col; j++)
{
p[id][j] = mut1[j];
}
}
}
double fti(int col, int * individu, double ** t, double ** tc)
{
double s1 = 0, s2 = 0;
for (int j = 0; j < col; j++)
{
s1 += t[individu[j]][j];
// p[i]{j]= N°Configuration [j]=N° de la
// tache
}
for (int j = 0; j < col - 1; j++)
{
s2 += tc[individu[j]][individu[j + 1]];
// p[i]{j]=
// N°Configuration
// [j+1]=N°configuration
// suivante dans la solution
// en cours
}
return s1 + s2;
}
double fci(int col, int * individu, double ** c, double ** cc)
{
double s1 = 0, s2 = 0;
for (int j = 0; j < col; j++)
{
s1 += c[individu[j]][j];
// p[i]{j]= N°Configuration [j]=N° de la
// tache
}
for (int j = 0; j < col - 1; j++)
{
s2 += cc[individu[j]][individu[j + 1]]; // p[i]{j]=
// N°Configuration
// [j+1]=N°configuration
// suivante dans la solution
// en cours
}
return s1 + s2;
}
SVP  .... aidez moi à trouver ce que je doit mettre comme paramètre dans les fonctions pour que l'algorithme marche. je serai très reconnaissant
merci beaucoup, je n'oublierai jamais votre soutien  .
|
|
samedi 18 juin 2011 à 17:05:00 |
Re : j'ai besoin de vous!!!

baster200x
|
désolé voilà un algorithme qui travail de la même façon:
NSGA_II:
---------
Code C/C++ :
#include <iostream>
#include <sstream>
#include <m3_object.h>
#include <m3_map.h>
#include <m3_vector.h>
#include <m3_shell_variables.h>
#include <m3_parser.h>
#include <m3_optimizer.h>
#include <m3_opt_utils.h>
#include <m3_sim_utils.h>
//#include <stdlib.h>
#include <stdio.h>
class m3_point_EA : public m3_point
{
public:
m3_point_EA();
m3_point_EA(m3_point &p);
m3_point_EA(const m3_point_EA &p);
int dominated_p;
int dominating_p;
vector<int> dominating_v;
int rank;
bool ranked;
bool evaluated;
bool edge;
double distance;
};
m3_point_EA::m3_point_EA():m3_point() {
dominating_p = 0;
evaluated = false;
ranked = false;
edge = false;
distance = 0.0;
}
m3_point_EA::m3_point_EA(m3_point &l):m3_point(l){
dominating_p = 0;
evaluated = false;
ranked = false;
edge = false;
distance = 0.0;
}
m3_point_EA::m3_point_EA(const m3_point_EA &l):m3_point(l){
dominating_p = 0;
rank = l.rank;
evaluated = l.evaluated;
ranked = false;
edge = false;
distance = 0.0;
}
class m3_nsga_II: public m3_optimizer
{
public:
m3_nsga_II() {}
string get_information();
void explore(m3_env *env);
private:
void get_valid_points(m3_env *env, vector<m3_point> &doe_orig, vector<m3_point_EA> &doe);
void compare_points(m3_env *env, vector<m3_point_EA> &doe);
void compare_this_point(m3_env *env, vector<m3_point_EA> & doe, m3_point_EA ¤t_point);
void rank_points(m3_env *env, vector<m3_point_EA> & doe_ranked, vector<m3_point_EA> & doe);
void diverse_points(m3_env *env, vector<m3_point_EA> &doe_ranked);
void generate_next_pop (m3_env *env, vector<m3_point_EA> &children,vector<m3_point_EA> &doe_ranked);
void select_best_half(m3_env *env, vector<m3_point_EA> &doe_ranked, vector<m3_point_EA> &doe_merged_ranked);
};
string m3_nsga_II::get_information()
{
return "Nondominated Sorting Genetic Algorithm II optimizer";
}
void m3_nsga_II::explore(m3_env *env)
{
prs_display_message("Starting with the NSGA-II optimization process");
m3_assert(env->current_driver);
bool temporary_save = false;
string filename;
if (get_string_from_variables(env, "temp_database", filename))
temporary_save = true;
vector<m3_point> doe_orig = env->current_doe->generate_doe(env);
int doe_orig_size = doe_orig.size();
char tempInt [20];
vector<m3_point_EA> doe;
get_valid_points(env, doe_orig, doe);
/*the main algorithm that compare the points regarding domination
this algorithm adds the following attributes to each point, the vector of dominated nodes,
the No. of dominated points and the No. of dominating points...*/
compare_points(env, doe);
for(int i = 0; i < doe.size(); i++)
{
prs_display_message("point: " + env->current_design_space->get_point_representation(env, doe[i]));
string error;
if(!doe[i].get_error(error))
{
for(int j = 0; j < env->current_design_space->objectives.size(); j++)
{
double my_value = doe[i].get_objective(env, j);
sprintf(tempInt,"%.0f",my_value);
prs_display_message(tempInt);
}
}
}
/*the main algorithm that rank the points by going through sccessive fronts
this algorithm adds the following attributes to each point
the rank No., it also sort the points by the rank No. in the first argument*/
vector<m3_point_EA> doe_ranked;
rank_points(env, doe_ranked, doe);
//compute the crowding parameter to support the diversity feature this algorithm adds average distance to indicate the crowding
diverse_points(env, doe_ranked);
int generations;
if(!get_integer_from_variables(¤t_environment,"generations", generations))
{
prs_display_message("No 'generations' defined; defaulting to 100 generations as stopping criteria");
generations = 100;
}
for(int genNo = 0; genNo<generations; genNo++)
{
//for each generaton the points would be already added in doe_ranked, so start by generating the new population
//produce the next population in children, by crossover and permutation
vector<m3_point_EA> children;
generate_next_pop (env, children, doe_ranked);
//merge the two populations parents "doe_ranked" and children to have population of double size
vector<m3_point_EA> doe_merged;
vector<m3_point_EA> doe_merged_ranked;
for(int i=0; i<doe_ranked.size(); i++)
doe_merged.push_back(doe_ranked[i]);
for(int i=0; i<children.size(); i++)
doe_merged.push_back(children[i]);
//should be empty for next generations
doe_ranked.clear();
children.clear();
//rank the new double size population, parents+children as previous, "compare_points", rank_points and "diverse_points"
compare_points(env, doe_merged);
rank_points(env, doe_merged_ranked, doe_merged);
diverse_points(env, doe_merged_ranked);
//create the new generation by getting the best N solutions of the 2N solutions,
//this process gurantees the eliticism
select_best_half(env, doe_ranked, doe_merged_ranked);
//should be empty for next generations
doe_merged.clear();
doe_merged_ranked.clear();
//now doe_ranked would be already ranked "best ranks are selected" but diversity should be computed again
//diverse_points(env, doe_ranked);
//now doe_ranked is considered the new generation
//cout << endl;
sprintf(tempInt,"%d",genNo);
prs_display_message("Generation No.: ");
prs_display_message(tempInt);
if (temporary_save)
{
prs_display_message("Writing temporary database..");
env->available_dbs["root"]->write_to_file(filename.c_str());
}
}
cout << endl;
}
void m3_nsga_II::get_valid_points(m3_env *env, vector<m3_point> &doe_orig, vector<m3_point_EA> &doe)
{
m3_point_EA current_point;
int doe_orig_size = doe_orig.size();
int doe_size = doe.size();
for (int i = 0; i < doe_orig_size ; i++)
{
current_point = doe_orig[i];
//it always return true if the used driver is "m3_driver" ,!!!
// but if the used driver is m3_xml_driver, it seems that it checks the rules
if(env->current_design_space->is_valid(env, & doe_orig[i]))
{
prs_display_message("Adding point: " + env->current_design_space->get_point_representation(env, current_point));
doe.push_back(current_point);
}
else
{
prs_display_message("Skipping point: " + env->current_design_space->get_point_representation(env,current_point));
}
}
}
void m3_nsga_II::compare_points(m3_env *env, vector<m3_point_EA> &doe)
{
prs_display_message("Comparing Points");
int exp_size = doe.size();
for(int experiment = 0; experiment < exp_size; experiment ++)
{
if(!doe[experiment].evaluated)
{
//m3_point ¤t_point = doe[experiment];
//prs_display_message("Evaluating point: " + env->current_design_space->get_point_representation(env, doe[experiment]));
//why the clear metrics should be called
//doe[experiment].clear_metrics(env);
env->current_design_space->evaluate(env, & doe[experiment]);
if(sim_recompute_pareto_with_new_point(env, env->available_dbs[env->current_db_name], &doe[experiment]))
{
if( env->available_dbs[env->current_db_name]->find_point(doe[experiment])==NULL )
env->available_dbs[env->current_db_name]->insert_point(& doe[experiment]);
}
doe[experiment].evaluated = true;
string error;
int err_code;
/*it seems that == operator should be replaced by the assignment
operator =, which returns false if the right hand expression = 0*/
err_code = doe[experiment].get_error(error);
if(err_code == M3_POINT_FATAL_ERROR)
break;
}
}
char tempInt [20];
int obj_size = env->current_design_space->objectives.size();
for(int experiment = 0; experiment < exp_size; experiment ++)
{
compare_this_point(env, doe, doe[experiment]);
}
}
void m3_nsga_II::compare_this_point(m3_env *env, vector<m3_point_EA> & doe, m3_point_EA & current_point)
{
int dominating_p = 0; // No. of points current_point domintates
int dominated_p = 0; // No. of points domintate current_point
int exp_size = doe.size();
int obj_size = env->current_design_space->objectives.size();
vector<int> dominating_v(exp_size); // dominating vector space
char tempInt [20];
string error;
if( current_point.get_error(error) ) // if the current point is an error point
{
for (int i=0; i<exp_size; i++)
{
if(!doe[i].get_error(error))
{
dominated_p++;
}
}
current_point.dominating_p = 0;
current_point.dominated_p = dominated_p;
return;
}
//for(int j = experiment+1; j < exp_size; j++)
for(int j = 0; j < exp_size; j++)
{
m3_point_EA compared_point = doe[j];
if (¤t_point != &compared_point) //don't compare a point to itself
{
if (!compared_point.get_error(error)) // if the compared point is not error point
{
bool m_worse=false;
bool c_worse=false;
//scan for objectives
for(int i=0; i < obj_size ;i++)
{
double my_value = current_point.get_objective(env, i);
double comp_value = compared_point.get_objective(env, i);
if (my_value>comp_value) m_worse=true;
if (comp_value>my_value) c_worse=true;
}
if(c_worse && !m_worse) //my current point dominates the compared
{
dominating_v[dominating_p] = j; //push the dominated point ID
dominating_p ++;
}
if(!c_worse && m_worse) //the compared point dominates my point
{
dominated_p ++;
}
}
else // error points are always dominated
{
dominating_v[dominating_p] = j; //push the dominated point ID
dominating_p ++;
}
}
}
current_point.dominating_p = dominating_p;
current_point.dominated_p = dominated_p;
current_point.dominating_v.clear();
for (int i=0; i<dominating_p; i++){
// cout << " d_v_i " << dominating_v[i] << endl;
current_point.dominating_v.push_back(dominating_v[i]);
}
}
void m3_nsga_II::rank_points(m3_env *env, vector<m3_point_EA> &doe_ranked, vector<m3_point_EA> &doe)
{
prs_display_message("Ranking Points");
int dominating_p;
int rank = 1;
char tempInt [20];
string temp;
string error;
for(int i = 0; i < doe.size(); i++)
doe[i].ranked = false;
while (doe_ranked.size() < doe.size())
{
bool changed=false;//will become true when only error points will remain
for(int i = 0; i < doe.size(); i++)
{
//if the point is an error point rank it now and modify it rank at the end as the maximum
if( (doe[i].get_error(error)) )
continue;
if(doe[i].ranked || doe[i].dominated_p)
continue; //already ranked or still not pareto jump to the next point
changed=true;
//pareto regarding this front
sprintf(tempInt,"%d",rank);
temp = tempInt;
ostringstream objs;
int obj_size = env->current_design_space->objectives.size();
for(int j=0; j < obj_size ;j++)
{
objs << doe[i].get_objective(env, j) << " ";
}
for (int j = 0; j < doe[i].dominating_p; j++)
{
//get points dominated by current_point, msut not be ranked yet
int index = doe[i].dominating_v[j];
if(doe[index].ranked)//an algorithmic error
prs_display_message("Algorithmic Error");
doe[index].dominated_p --;
if(doe[index].dominated_p < 0)//an algorithmic error
prs_display_message("Algorithmic Error");
}
doe[i].rank = rank;
doe[i].ranked = true;
doe_ranked.push_back(doe[i]);
}
rank ++;
//missing only error points
if(!changed){
for(int i = 0; i < doe.size(); i++){
if((doe[i].get_error(error))){
doe[i].rank = rank;
doe[i].ranked = true;
doe_ranked.push_back(doe[i]);
}
}
}
}
}
void m3_nsga_II::generate_next_pop (m3_env *env, vector<m3_point_EA> &children, vector<m3_point_EA> &doe_ranked)
{
prs_display_message("Generating Next Pop");
while(children.size() < doe_ranked.size())
{
int randNo1 = rand()%doe_ranked.size();
int randNo2 = rand()%doe_ranked.size();
int randNo3 = rand()%doe_ranked.size();
int randNo4 = rand()%doe_ranked.size();
int parentNo1;
int parentNo2;
if (doe_ranked[randNo1].rank < doe_ranked[randNo2].rank)
parentNo1 = randNo1;
else if(doe_ranked[randNo2].rank < doe_ranked[randNo1].rank)
parentNo1 = randNo2;
else //the same rank
{
if(doe_ranked[randNo1].edge) //point on the edge, injfinite crowding distance
parentNo1 = randNo1;
else if(doe_ranked[randNo2].edge) //point on the edge, injfinite crowding distance
parentNo1 = randNo2;
else
{
if(doe_ranked[randNo1].distance > doe_ranked[randNo2].distance)
parentNo1 = randNo1;
else
parentNo1 = randNo2;
}
}
if (doe_ranked[randNo3].rank < doe_ranked[randNo4].rank)
parentNo2 = randNo3;
else if(doe_ranked[randNo4].rank < doe_ranked[randNo3].rank)
parentNo2 = randNo4;
else //the same rank
{
if(doe_ranked[randNo3].edge) //point on the edge, injfinite crowding distance
parentNo2 = randNo3;
else if(doe_ranked[randNo4].edge) //point on the edge, injfinite crowding distance
parentNo2 = randNo4;
else
{
if(doe_ranked[randNo3].distance > doe_ranked[randNo4].distance)
parentNo2 = randNo3;
else
parentNo2 = randNo4;
}
}
m3_point parent1 = doe_ranked[parentNo1];
m3_point parent2 = doe_ranked[parentNo2];
m3_point cross_p = env->current_design_space->genetic_crossover(env, &parent1, &parent2);
m3_point perm_p = env->current_design_space->genetic_mutation(env, &cross_p, 0.1);
if(env->current_design_space->is_valid(env, & perm_p))
{
prs_display_message("Adding point: " + env->current_design_space->get_point_representation(env, perm_p));
children.push_back(perm_p);
}
else
{
prs_display_message("Skipping point: " + env->current_design_space->get_point_representation(env, perm_p));
}
}
prs_display_message("Finished Generating Next Pop");
}
void m3_nsga_II::select_best_half(m3_env *env, vector<m3_point_EA> &doe_ranked, vector<m3_point_EA> &doe_merged_ranked)
{
prs_display_message("Selecting Best half");
int rank = 1, count=0, lastCount=0;
int doe_merged_size = doe_merged_ranked.size();
int first = 0;
for(int p=0; p<doe_merged_size; p++)
{
if(doe_merged_ranked[p].rank == rank && (p!=(doe_merged_size-1))) //check the end of input vector
continue;
if(p<doe_merged_size/2) //all this front should be taken, and should continue with next fronts
{
for(int i=first; i<p; i++)
{
doe_ranked.push_back(doe_merged_ranked[i]);
}
rank++;
first = p;
continue;
}
else if(p==doe_merged_size/2) //all this front should be taken, and should stop taking next fronts
{
for(int i=first; i<p; i++)
{
doe_ranked.push_back(doe_merged_ranked[i]);
}
break;
}
else //parts of this front should be taken, and then stop
{
for(int i=first; i<p; i++) //take any point at the edge
{
if(doe_merged_ranked[i].edge)
{
doe_ranked.push_back(doe_merged_ranked[i]);
if(doe_ranked.size() == doe_merged_size/2)
break; //stop, so break the inner loop then the outer loop
}
}
while(doe_ranked.size() < doe_merged_size/2)
{
double highestDist = 0;
int index = 0;
for(int i=first; i<p; i++) //take the points with highest distance, one by one, all the points at the edge aleady taken
{
if(!doe_merged_ranked[i].edge) //eligible point
{
if(doe_merged_ranked[i].distance > highestDist)
{
highestDist = doe_merged_ranked[i].distance;
index = i;
}
}
}
doe_ranked.push_back(doe_merged_ranked[index]);
doe_merged_ranked[index].edge = true; //don't consider it next time
}
break;
}
}
char tempInt [20];
}
//asuming that the vector is ranked and sorted.
void m3_nsga_II::diverse_points(m3_env *env, vector<m3_point_EA> &doe_ranked)
{
int first=0, rank=1;
int obj_size = env->current_design_space->objectives.size();
double *lowest = new double [obj_size];
double *highest = new double [obj_size];
for(int i = 0; i < doe_ranked.size(); i++)
doe_ranked[i].edge = false;
for(int p=0; p<doe_ranked.size(); p++)
{
string error;
if( (doe_ranked[p].rank == rank) || (doe_ranked[p].get_error(error)) )
continue;
else
{ //points belong to the same nondominating front, from first to i-1
for(int k=0; k<obj_size; k++)
{
lowest[k]=doe_ranked[first].get_objective(env, k);
highest[k]=doe_ranked[first].get_objective(env, k);
}
for(int j=first+1; j<p; j++)
{
for(int k=0; k<obj_size; k++)
{
if(doe_ranked[j].get_objective(env, k) < lowest[k])
lowest[k]=doe_ranked[j].get_objective(env, k);
if(doe_ranked[j].get_objective(env, k) > highest[k])
highest[k]=doe_ranked[j].get_objective(env, k);
}
}
for(int j=first; j<p; j++)
{
double distance = 0;
for(int k=0; k<obj_size; k++)
{
double dist2lower = doe_ranked[j].get_objective(env,k)-lowest[k];
double dist2higher = highest[k]-doe_ranked[j].get_objective(env,k);
if((dist2higher==0)||(dist2lower==0)) //point on the edge
{
doe_ranked[j].edge = true; //equivelent to distance of infinity
doe_ranked[j].distance = 0;
break;
}
for(int l=first; l<p; l++)
{
if(l==j) //don't compare a point to itself
continue;
else
{
int diff = doe_ranked[j].get_objective(env,k)-doe_ranked[l].get_objective(env,k);
if(diff <= 0) //the point j is lower than l, higher value may be updated
{
if (diff < dist2higher)
dist2higher = diff;
}
if(diff >= 0) //the point j is higher than l, lower value may be updated
{
if (diff < dist2lower)
dist2lower = diff;
}
}
} //end of compared point scanning
distance = distance + (dist2lower+dist2higher)/(highest[k]-lowest[k]);
} //end of objectives scanning
doe_ranked[j].distance = distance;
} //end of scanning this nondominating front
first = p; //begin of a new non dominating front
}
}
delete [] lowest;
delete [] highest;
}
extern "C"
{
m3_optimizer *opt_generate_optimizer()
{
return new m3_nsga_II();
}
}
|
|
jeudi 30 juin 2011 à 10:16:35 |
Re : j'ai besoin de vous!!!

baster200x
|
BONJOUR .
JE voix qu'il y a personne pour m'aider... j'ai voulu juste savoir quel paramètre utilise dans le premier algorithme .. je sais que je doit utilisé les paramètre suivants:
m3point pour modeliser les points
m3_env te permettra de récuperer tout ce qui concerne les entrées et les sorties ainsi que le plan d’expérience sélectionné par exemple
et autre objet pour faire tourner le code comme m3_map, m3_vector, m3_parser, ....
y on a surement d'autre mais je les connais pas et pour cela j'ai demander l'aide de vous car vous savez plus que moi en programment avec C/C++
merci pour votre aide !
|
|
Cette discussion est classée dans : int, col, for, double, lig
Répondre à ce message
Sujets en rapport avec ce message
problème d'intégrer mon algorithme [ par baster200x ]
Slt tous le mande! je vous adresse pour m'aider à trouver une solution à mon problème! j'ai un outil Open source Nommé [url=http://home.dei.polimi
Besoin d'aide urgent SVP [ par paulina82 ]
Bonjour, j'ai un gros probleme avec mon programme ecri en langage C.lorsque je complile il n'afiche pa d'erreur mais lorsque j'esaye de l'executé il
allocation dynamique [ par CeNedra83 ]
je code en C++ en je ne comprend pas un truc: ma fonction marchait très bien et maintenant elle se met à planter une fois sur 2 pour cause d'allocatio
algorithmique de fonction rec [ par fs_fck_sarko ]
bonjour tout le monde, est ce que quelquun pourai maider pour le calul de complexite d'un programme qui resout les sudoku ? En fait je voudrais trouve
appel de fontions avec un tableau de pointeurs en paramèmtre [ par thespartan ]
Voilà j'ai cette fonction qui marche :void alloue(int lig,int col){int i,j; int l='A'; T = (int **) malloc(col*sizeof(int*)); if (T == NULL) pri
Aide partie résolution de mon sudoku... [ par Francks11 ]
Bonsoir, enfaite il me faudrait de l'aide pour ma partie sol du sudoko qui recherche les solutions du jeu. A savoir, que pour chaque essai, on conser
Segmentation Fault....en traitement d'image [ par psysta ]
Bonjour,je suis nouveau dans la programmation en C. J'ai un programme Matlab qui marche bien, et je souhaiterais l'implémenter en C. Le pgm compile bi
Besoin d'aide c++ [ par sevio14 ]
Quelqu'un peut-il m'aider à faire le programme de l'algorithme d'uzawa? Voici ce que j'ai commencé à définir: #include #include #include #includ
Programme en c++ [ par noussa44 ]
Bonjour à tous et merci d'avance pour vos réponses, J'ai fait un petit code en c++ pou calculer la distance entre des points avec la formule :d² = (x'
[QT] vider QGridLayout et rafraichir sont affichage [ par yepraoulette ]
Salut a tous,Je cherche en faite a afficher une partie d'un tableau (stocké dans une QList de QList) dans un GridLayoutL'utilisateur peut choisir le n
Livres en rapport
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|