IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual C++ Discussion :

Problème de lien fichier de données


Sujet :

Visual C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 116
    Par défaut Problème de lien fichier de données
    Bonjour tout le monde,

    Je suis depuis longtemps sur ce problème.

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    /
     
    #include <cplex.h>
     
    #include <ctype.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
     
     
    /* Include declarations for functions in this program */
     
    static void
       free_and_null (char **ptr);
     
     
    int
    main (void)
    {
       CPXENVptr env = NULL;
       CPXLPptr  lp = NULL;
       int       status = 0;
       int       j;
       int       numcols;
       double    totinv; 
     
       int       solstat;
       double    objval;
       double    *x = NULL;
     
       double    rrhs[1];
       char      rsense[1];
       int       rmatbeg[1];
     
       int       *indices = NULL;
       double    *values = NULL;
       char      *namestore = NULL;
       char      **nameptr = NULL;
       int       surplus, storespace;
     
     
       /* Initialize the CPLEX environment */
     
       env = CPXopenCPLEX (&status);
     
       /* If an error occurs, the status value indicates the reason for
          failure.  A call to CPXgeterrorstring will produce the text of
          the error message.  Note that CPXopenCPLEX produces no output,
          so the only way to see the cause of the error is to use
          CPXgeterrorstring.  For other CPLEX routines, the errors will
          be seen if the CPX_PARAM_SCRIND indicator is set to CPX_ON.  */
     
       if ( env == NULL ) {
          char  errmsg[1024];
          fprintf (stderr, "Could not open CPLEX environment.\n");
          CPXgeterrorstring (env, status, errmsg);
          fprintf (stderr, "%s", errmsg);
          goto TERMINATE;
       }
     
       /* Turn on output to the screen */
     
       status = CPXsetintparam (env, CPX_PARAM_SCRIND, CPX_ON);
       if ( status ) {
          fprintf (stderr, 
                   "Failure to turn on screen indicator, error %d.\n", status);
          goto TERMINATE;
       }
     
       /* Create the problem, using the filename as the problem name */
     
       lp = CPXcreateprob (env, &status, "prod.lp");
     
       /* A returned pointer of NULL may mean that not enough memory
          was available or there was some other problem.  In the case of 
          failure, an error message will have been written to the error 
          channel from inside CPLEX.  In this example, the setting of
          the parameter CPX_PARAM_SCRIND causes the error message to
          appear on stdout.  Note that most CPLEX routines return
          an error code to indicate the reason for failure.   */
     
       if ( lp == NULL ) {
          fprintf (stderr, "Failed to create LP.\n");
          goto TERMINATE;
       }
     
       /* Now read the file, and copy the data into the created lp */
     
       status = CPXreadcopyprob (env, lp, "../../data/prod.lp", NULL);
       if ( status ) {
          fprintf (stderr, "Failed to read and copy the problem data.\n");
          goto TERMINATE;
       }
     
       /* Tell presolve to do only primal reductions,
          turn off simplex logging */
     
       status = CPXsetintparam (env, CPX_PARAM_REDUCE, 1) ||  
                CPXsetintparam (env, CPX_PARAM_SIMDISPLAY, 0);
     
       if ( status ) {
          fprintf (stderr, "Failure to set parameters\n");
          goto TERMINATE;
       } 
     
     
       /* Optimize the problem and obtain solution. */
     
       status = CPXlpopt (env, lp);
       if ( status ) {
          fprintf (stderr, "Failed to optimize profit LP.\n");
          goto TERMINATE;
       }
     
       solstat = CPXgetstat (env, lp);
       status  = CPXgetobjval (env, lp, &objval);
     
       if ( status || solstat != CPX_STAT_OPTIMAL ) {
          fprintf (stderr, "Solution failed. Status %d, solstat %d.\n",
                   status, solstat);
          goto TERMINATE;
       }
       printf ("Profit objective value is %g\n", objval);
     
     
       /* Allocate space for column names */
     
       numcols = CPXgetnumcols (env, lp);
       if ( !numcols ) {
          fprintf (stderr, "No columns in problem\n");
          goto TERMINATE;
       }
     
       CPXgetcolname (env, lp, NULL, NULL, 0, &surplus, 0, numcols-1);
       storespace = - surplus;
     
       namestore = (char *) malloc (storespace * sizeof(char));
       nameptr   = (char **) malloc (numcols * sizeof(char *));
       if ( namestore == NULL  ||  nameptr == NULL ) {
          fprintf (stderr, "No memory for column names\n");
          goto TERMINATE;
       }
     
       status = CPXgetcolname (env, lp, nameptr, namestore, storespace,
                               &surplus, 0, numcols-1);
       if ( status ) {
          fprintf (stderr, "Failed to get column names\n");
          goto TERMINATE;
       }
     
       /* Allocate space for solution */
     
       x = (double *) malloc (numcols * sizeof(double));
     
       if ( x == NULL ) {
          fprintf (stderr,"No memory for solution.\n");
          goto TERMINATE;
       }
     
       status = CPXgetx (env, lp, x, 0, numcols-1);
       if ( status ) {
          fprintf (stderr, "Failed to obtain primal solution.\n");
          goto TERMINATE;
       }
     
       totinv = 0;
       for (j = 0; j < numcols; j++) {
          if ( !strncmp (nameptr[j], "inv", 3) )  totinv += x[j];
       }
       printf ("Inventory level under profit objective is %g\n", totinv);
     
       /* Allocate space for a constraint */
     
       indices = (int *)    malloc (numcols * sizeof (int));
       values  = (double *) malloc (numcols * sizeof (double));
     
       if ( indices == NULL  ||  values == NULL ) {
          fprintf (stderr, "No memory for constraint\n");
          goto TERMINATE;
       }
     
       /* Get profit objective and add it as a constraint */
     
       status = CPXgetobj (env, lp, values, 0, numcols-1);
       if ( status ) {
          fprintf (stderr,
                  "Failed to get profit objective.  Status %d\n", status);
          goto TERMINATE;
       }
       for (j = 0; j < numcols; j++) {
          indices[j] = j;
       }
     
       rrhs[0]    = objval - fabs (objval) * 1e-6;
       rsense[0]  = 'G';
       rmatbeg[0] = 0;
     
       status = CPXpreaddrows (env, lp, 1, numcols, rrhs, rsense,
                               rmatbeg, indices, values, NULL);
     
       if ( status ) {
          fprintf (stderr,
                  "Failed to add objective as constraint.  Status %d\n",
                  status);
          goto TERMINATE;
       }
     
       /* Set up objective to maximize negative of sum of inventory */
     
       totinv = 0;
       for (j = 0; j < numcols; j++) {
          if ( strncmp (nameptr[j], "inv", 3) ) {
             values[j] = 0.0;
          }
          else {
             values[j] = - 1.0;
          }
       }
     
       status = CPXprechgobj (env, lp, numcols, indices, values);
     
       if ( status ) {
          fprintf (stderr,
                  "Failed to change to inventory objective.  Status %d\n",
                  status);
          goto TERMINATE;
       }
     
       status = CPXlpopt (env, lp);
       if ( status ) {
          fprintf (stderr, "Optimization on inventory level failed. Status %d.\n",
                  status);
          goto TERMINATE;
       }
     
       solstat = CPXgetstat (env, lp);
       status  = CPXgetobjval (env, lp, &objval);
       if ( status  ||  solstat != CPX_STAT_OPTIMAL ) {
          fprintf (stderr, "Solution failed. Status %d, solstat %d.\n",
                   status, solstat);
          goto TERMINATE;
       }
     
       printf ("Inventory level after optimization is %g\n", -objval);
     
     
       status = CPXgetx (env, lp, x, 0, numcols-1);
       if ( status ) {
          fprintf (stderr, "Failed to obtain primal solution.\n");
          goto TERMINATE;
       }
     
       /* Write out the solution */
     
       printf ("\n");
       for (j = 0; j < numcols; j++) {
          printf ( "%s:  Value = %17.10g\n", nameptr[j], x[j]);
       }
     
     
    TERMINATE:
     
       /* Free up the basis and solution */
     
       free_and_null ((char **) &indices);
       free_and_null ((char **) &values);
       free_and_null ((char **) &nameptr);
       free_and_null ((char **) &namestore);
       free_and_null ((char **) &x);
     
     
       /* Free up the problem, if necessary */
     
       if ( lp != NULL ) {
          status = CPXfreeprob (env, &lp);
          if ( status ) {
             fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status);
          }
       }
     
       /* Free up the CPLEX environment, if necessary */
     
       if ( env != NULL ) {
          status = CPXcloseCPLEX (&env);
     
          /* Note that CPXcloseCPLEX produces no output,
             so the only way to see the cause of the error is to use
             CPXgeterrorstring.  For other CPLEX routines, the errors will
             be seen if the CPX_PARAM_SCRIND indicator is set to CPX_ON. */
     
          if ( status ) {
             char  errmsg[1024];
             fprintf (stderr, "Could not close CPLEX environment.\n");
             CPXgeterrorstring (env, status, errmsg);
             fprintf (stderr, "%s", errmsg);
          }
       }
     
       return (status);
     
    }  /* END main */
     
     
     
     
    /* This simple routine frees up the pointer *ptr, and sets *ptr to NULL */
     
    static void
    free_and_null (char **ptr)
    {
       if ( *ptr != NULL ) {
          free (*ptr);
          *ptr = NULL;
       }
       getchar();
    } /* END free_and_null */
    Console :

    Des idées??
    Merci!

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 485
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 485
    Par défaut
    ???
    Vérifiez le chemin vers "prod.lp".

    Moi, c'est madame Irma.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 116
    Par défaut
    Merci pour votre réponse.
    En fait, c'est la correction d'un exercice de classe qui nous avez envoyé notre professeur sous format de deux fichiers séparés : fichier source, fichier donnée.
    Je ne vois pas comment indiquer au compilateur le chemin vers le fichier "prod.lp"?

  4. #4
    Membre éprouvé
    Avatar de TheGzD
    Homme Profil pro
    Ingénieur/ Docteur en Informatique
    Inscrit en
    Avril 2007
    Messages
    1 327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Ingénieur/ Docteur en Informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 327
    Par défaut
    Tu n'as pas l'air d'avoir réalisé que c'est ton programme qui t'affiche ça et non ton compilateur ...

    Commence déjà par lire le code qu'on t'a fourni et remplace le chemin relatif du fichier par celui (relatif ou absolu) qui correspondra à celui du fichier dans ton environnement d'exécution.

    De sérieuses (ré)visions de tes cours semblent s'imposer

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 116
    Par défaut
    Je ne cherche pas à voir une réponse complète mais un indice.
    Quelle est la ligne de code à changer pour modifier le chemin de fichier de donnée?

  6. #6
    Membre éprouvé
    Avatar de TheGzD
    Homme Profil pro
    Ingénieur/ Docteur en Informatique
    Inscrit en
    Avril 2007
    Messages
    1 327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Ingénieur/ Docteur en Informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 327
    Par défaut
    Citation Envoyé par laureat Voir le message
    Je ne cherche pas à voir une réponse complète mais un indice.
    Quelle est la ligne de code à changer pour modifier le chemin de fichier de donnée?
    Commence par lire ce que je t'ai écrit, car j'y ai tout dit.

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 116
    Par défaut
    En fait, je n'ai pas utilisé cet environnement mais je l'aurais besoin pour faire mon pfe.
    Je suis bloqué c'est pour celà je vous sollicite votre aide.
    Merci pour votre compréhension.
    Revenons alors
    ??
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    /
     
       /* Create the problem, using the filename as the problem name */
     
       lp = CPXcreateprob (env, &status, "prod.lp");
     
       /* A returned pointer of NULL may mean that not enough memory
          was available or there was some other problem.  In the case of 
          failure, an error message will have been written to the error 
          channel from inside CPLEX.  In this example, the setting of
          the parameter CPX_PARAM_SCRIND causes the error message to
          appear on stdout.  Note that most CPLEX routines return
          an error code to indicate the reason for failure.   */
     
       if ( lp == NULL ) {
          fprintf (stderr, "Failed to create LP.\n");
          goto TERMINATE;
       }
     
       /* Now read the file, and copy the data into the created lp */
     
       status = CPXreadcopyprob (env, lp, "../../data/prod.lp", NULL);
       if ( status ) {
          fprintf (stderr, "Failed to read and copy the problem data.\n");
          goto TERMINATE;
       }

  8. #8
    Membre éprouvé
    Avatar de TheGzD
    Homme Profil pro
    Ingénieur/ Docteur en Informatique
    Inscrit en
    Avril 2007
    Messages
    1 327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Ingénieur/ Docteur en Informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 327
    Par défaut
    En fait, je n'ai pas utilisé cet environnement
    mais de quoi parles-tu ? n'as-tu pas essayé de compiler les sources ? n'as-tu pas lancé le programme obtenu ?

    Citation Envoyé par bacelar
    Moi, c'est madame Irma.
    donnerais-tu comme bacelar dans la divination ?


  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 116
    Par défaut
    Citation Envoyé par TheGzD Voir le message

    donnerais-tu comme bacelar dans la divination ?
    non!

  10. #10
    Membre éprouvé
    Avatar de TheGzD
    Homme Profil pro
    Ingénieur/ Docteur en Informatique
    Inscrit en
    Avril 2007
    Messages
    1 327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Ingénieur/ Docteur en Informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 327
    Par défaut
    Je pense que ton professeur est là pour répondre à ce type de question.
    +1 encore faut il se donner la peine d'un petit effort personnel afin de cibler ce qui nous pose problème.

    Google aussi pour répondre à certaines questions : par exemple en cherchant "environnement d'exécution"

    En fait, je n'ai pas utilisé cet environnement
    Tu auras donc du mal à lancer un programme sans en avoir un ...

  11. #11
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 485
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 485
    Par défaut
    Bon, ton "pfe" donne du code tout pourri.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    status = CPXreadcopyprob (env, lp, "../../data/prod.lp", NULL);
    C'est un chemin qui semble relatif au répertoire de travail de l'exécutable.

    Si le répertoire "data" n'existe pas dans le répertoire grand-père du répertoire de travail de l'exécutable, cela risque de ne pas marcher.
    Je pense que le répertoire de travail est celui qui contient le fichier "prod.lp".

    Je pense que ton professeur est là pour répondre à ce type de question.

Discussions similaires

  1. [XL-2003] Problème de lien vers imprimante = lenteur fichier
    Par Franck_P dans le forum Excel
    Réponses: 1
    Dernier message: 23/09/2009, 07h16
  2. Réponses: 8
    Dernier message: 25/11/2008, 12h33
  3. Problème de Lien avec la base de données
    Par EricDou dans le forum Langage
    Réponses: 4
    Dernier message: 15/05/2007, 14h19
  4. Problème de lien vers un fichier local
    Par Alain15 dans le forum Langage
    Réponses: 17
    Dernier message: 20/07/2006, 15h51
  5. [Upload] Problème de lien entre mes fichiers
    Par temperature dans le forum Langage
    Réponses: 18
    Dernier message: 25/04/2006, 12h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo