ajout de l'utilisation des y1, y2... mais du coup faut corriger les erreurs parce que je suis un sgueg mdr
This commit is contained in:
parent
b56464f954
commit
aae7a4d58b
12
src/master.c
12
src/master.c
@ -47,7 +47,7 @@ int perfect_rolls() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int nb_coeffs = 4;
|
int nb_coeffs = 4;
|
||||||
double y1, y2, y3, y4;
|
double y[4] = {0};
|
||||||
int a[5] = {0};
|
int a[5] = {0};
|
||||||
glp_smcp params = {0};
|
glp_smcp params = {0};
|
||||||
glp_init_smcp(¶ms);
|
glp_init_smcp(¶ms);
|
||||||
@ -64,13 +64,13 @@ int perfect_rolls() {
|
|||||||
|
|
||||||
/* solve problem */
|
/* solve problem */
|
||||||
glp_simplex(lp, ¶ms);
|
glp_simplex(lp, ¶ms);
|
||||||
y1 = glp_get_row_dual(lp, 1);
|
y[0] = glp_get_row_dual(lp, 1);
|
||||||
y2 = glp_get_row_dual(lp, 2);
|
y[1] = glp_get_row_dual(lp, 2);
|
||||||
y3 = glp_get_row_dual(lp, 3);
|
y[2] = glp_get_row_dual(lp, 3);
|
||||||
y4 = glp_get_row_dual(lp, 4);
|
y[3] = glp_get_row_dual(lp, 4);
|
||||||
|
|
||||||
puts("Résolution du sous-problème.");
|
puts("Résolution du sous-problème.");
|
||||||
column_generator(y1, y2, y3, y4, a);
|
column_generator(y, a);
|
||||||
if (a[0] > 1) {
|
if (a[0] > 1) {
|
||||||
printf(" Valeur de l’objectif : %d\n", a[0]);
|
printf(" Valeur de l’objectif : %d\n", a[0]);
|
||||||
fputs(" On ajoute : ", stdout);
|
fputs(" On ajoute : ", stdout);
|
||||||
|
12
src/sub.c
12
src/sub.c
@ -4,18 +4,18 @@
|
|||||||
#include <glpk.h>
|
#include <glpk.h>
|
||||||
|
|
||||||
|
|
||||||
static void add_column_sp(glp_prob *lp, int *num_col_sp) {
|
static void add_column_sp(glp_prob *lp, int *num_col_sp, int coeff) {
|
||||||
glp_add_cols(lp, 1);
|
glp_add_cols(lp, 1);
|
||||||
char name[10] = "";
|
char name[10] = "";
|
||||||
snprintf(name, sizeof name, "rouleau%d", *num_col_sp);
|
snprintf(name, sizeof name, "rouleau%d", *num_col_sp);
|
||||||
glp_set_col_name(lp, *num_col_sp, name);
|
glp_set_col_name(lp, *num_col_sp, name);
|
||||||
glp_set_col_bnds(lp, *num_col_sp, GLP_LO, 0.0, 0.0);
|
glp_set_col_bnds(lp, *num_col_sp, GLP_LO, 0.0, 0.0);
|
||||||
glp_set_obj_coef(lp, *num_col_sp, 1.0);
|
glp_set_obj_coef(lp, *num_col_sp, coeff);
|
||||||
(*num_col_sp)++;
|
(*num_col_sp)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void column_generator(int y1, int y2, int y3, int y4, int a[static 5]) {
|
void column_generator(double y[static 4], int a[static 5]) {
|
||||||
glp_prob *sous_prob;
|
glp_prob *sous_prob;
|
||||||
int ia[1 + 1000];
|
int ia[1 + 1000];
|
||||||
int ja[1 + 1000];
|
int ja[1 + 1000];
|
||||||
@ -28,15 +28,15 @@ void column_generator(int y1, int y2, int y3, int y4, int a[static 5]) {
|
|||||||
glp_set_obj_dir(sous_prob, GLP_MAX);
|
glp_set_obj_dir(sous_prob, GLP_MAX);
|
||||||
|
|
||||||
/* fill problem */
|
/* fill problem */
|
||||||
glp_add_rows(sous_prob, 4);
|
glp_add_rows(sous_prob, 1);
|
||||||
glp_set_row_name(sous_prob, 1, "taille0");
|
glp_set_row_name(sous_prob, 1, "somme<=100");
|
||||||
glp_set_row_bnds(sous_prob, 1, GLP_UP, 0.0, 100.0);
|
glp_set_row_bnds(sous_prob, 1, GLP_UP, 0.0, 100.0);
|
||||||
|
|
||||||
int num_col_sp = 1;
|
int num_col_sp = 1;
|
||||||
|
|
||||||
const double coeffs[] = {45.0, 36.0, 31.0, 14.0};
|
const double coeffs[] = {45.0, 36.0, 31.0, 14.0};
|
||||||
for (int i = 1; i < 5; i++) {
|
for (int i = 1; i < 5; i++) {
|
||||||
add_column_sp(sous_prob, &num_col_sp);
|
add_column_sp(sous_prob, &num_col_sp, y[i-1]); //on prend y1, y2, y3 puis y4 (stockés dans y[0], y[1]...)
|
||||||
glp_set_col_kind(sous_prob, i, GLP_IV);
|
glp_set_col_kind(sous_prob, i, GLP_IV);
|
||||||
ia[i] = 1;
|
ia[i] = 1;
|
||||||
ja[i] = i;
|
ja[i] = i;
|
||||||
|
Reference in New Issue
Block a user