00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00102 #include <stdio.h>
00103 #include <string.h>
00104 #include <stdlib.h>
00105 #include "choquet.h"
00106 #include "image.h"
00107 #include "proto2D.h"
00108 #include "math.h"
00109
00110
00111
00129
00130
00131
00132
00133
00134
00135
00136
00137 param *choquet_interaction_lect(choquet_interaction_t *desc1, param *ptp, char *debq){
00138 char question[500];
00139
00140 sprintf(question, "%s choquet_interaction: nom complet du fichier", debq);
00141 lec_param(question, ptp);
00142 strcpy(desc1->fichier, ptp->rep);
00143 ptp = ptp->next;
00144
00145 return(ptp);
00146 }
00147
00148
00149
00150
00171 int choquet_interaction_init(choquet_interaction_t *desc2)
00172 {
00173
00174
00175 int l,c;
00176 FILE *fp;
00177 float somme,intercoeff;
00178
00179
00180
00181 (desc2->erreur)= AUCUNE_ERREUR;
00182
00183
00184 printf("-> Ouverture fichier en cours...");
00185 fp = fopen(desc2->fichier,"rt");
00186
00187 if(fp == NULL)
00188 {
00189 printf("\t\tECHEC.\n");
00190 desc2->erreur = ERREUR_CHOQUET_FILE;
00191 return 1;
00192 }
00193
00194 else
00195 {
00196 printf("\t\tOK.\n");
00197
00198
00199 printf("-> Initialisation de nbcoeff en cours...");
00200 fscanf(fp,"%d",&(desc2->nbcoeff));
00201 printf("\tNbcoeff = %d.\n",desc2->nbcoeff);
00202
00203
00204
00205 printf("-> Allocation memoire en cours...");
00206 (desc2->ptparam) = (parametre *)malloc((desc2->nbcoeff)*sizeof(parametre));
00207 printf("\t\tOK.\n");
00208
00209
00210 printf("-> Allocation cases matrice en cours...");
00211 for(l=0;l<(desc2->nbcoeff);l++)
00212 (desc2->ptparam[l])=(float *)malloc( (desc2->nbcoeff)*sizeof(float));
00213 printf("\t\tOK.\n");
00214
00215
00216
00217
00218
00219 intercoeff = 0.0;
00220
00221 for(l=0;l<(desc2->nbcoeff);l++)
00222 {
00223
00224
00225 if(intercoeff != EOF)
00226 {
00227 for(c=l;c<(desc2->nbcoeff);c++)
00228 {
00229
00230 fscanf(fp,"%f",&intercoeff);
00231
00232
00233 if(intercoeff != EOF)
00234 {
00235 (desc2->ptparam[l][c]) = intercoeff;
00236
00237
00238 (desc2->ptparam[c][l]) = (desc2->ptparam[l][c]);
00239
00240 }
00241 else
00242 {
00243
00244 (desc2->erreur) = ERREUR_CHOQUET_LIGNE_MATRICE;
00245 return 1;
00246 }
00247
00248
00249 }
00250
00251 }
00252 else
00253 {
00254 (desc2->erreur) = ERREUR_CHOQUET_COLONNE_MATRICE;
00255 return 1;
00256 }
00257
00258 }
00259
00260 fclose(fp);
00261
00262
00263
00264
00265
00266
00267 somme = 0.0;
00268 for(l=0;l<(desc2->nbcoeff);l++)
00269 somme += desc2->ptparam[l][l];
00270
00271 printf("-> La somme des nu_i est \t\t\t%1.4f\n",somme);
00272
00273 if(somme != 1)
00274 {
00275 desc2->erreur = ERREUR_CHOQUET_NU;
00276
00277 return 1;
00278 }
00279
00280
00281
00282
00283 for(l=0;l<(desc2->nbcoeff);l++)
00284 {
00285
00286
00287 somme = 0.0;
00288
00289
00290 for(c=0;c<(desc2->nbcoeff);c++)
00291 {
00292 somme = somme + fabs(desc2->ptparam[l][c]);
00293
00294 }
00295
00296
00297 if(somme > (3*(desc2->ptparam[l][l])))
00298 {
00299 (desc2->erreur) = ERREUR_CHOQUET_INTERACTION;
00300
00301 return 1;
00302 }
00303 }
00304
00305 return 0;
00306 }
00307 }
00308
00309
00310
00311
00325 int choquet_interaction_calc(choquet_interaction_t *desc3,float *donnee,float *resultat)
00326 {
00327
00328 float somme_prop,somme_inter;
00329 int l,c;
00330
00331 if(desc3->erreur == AUCUNE_ERREUR)
00332 {
00333
00334 somme_prop = 0.0;
00335
00336
00337 for(l=0;l<(desc3->nbcoeff);l++)
00338 somme_prop = somme_prop + donnee[l]*(desc3->ptparam[l][l]);
00339
00340
00341
00342
00343 somme_inter = 0.0;
00344
00345
00346 for(l=0;l<(desc3->nbcoeff);l++)
00347 for(c=l+1;c<(desc3->nbcoeff);c++)
00348 somme_inter = somme_inter + (desc3->ptparam[l][c])*fabs(donnee[c]-donnee[l]);
00349
00350
00351
00352
00353
00354
00355 *resultat = somme_prop - 0.5*somme_inter;
00356
00357 return 0;
00358 }
00359 else
00360 {
00361 printf("\nCalcul impossible car probleme a l'initialisation.\n");
00362
00363 return 1;
00364 }
00365
00366
00367 }
00368
00369
00370
00371
00383 int choquet_interaction_ferm(choquet_interaction_t *desc4)
00384 {
00385
00386 int ligne;
00387
00388
00389
00390 for (ligne=0;ligne<(desc4->nbcoeff);ligne++)
00391 free(desc4->ptparam[ligne]);
00392
00393 free(desc4->ptparam);
00394
00395 return 0;
00396 }
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415