help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Help: How to build MIP model


From: lucacoopers
Subject: Re: [Help-glpk] Help: How to build MIP model
Date: Fri, 4 Jan 2013 03:35:31 -0800 (PST)

Hi Raniere Silva.
Thank you so much for your help.
I need to build the model with the c language without using the mathprog and
standalone solver.

an example of code to resolve a minimization problem that I have is as
follows:

/* provaglpk.c */

#include <stdio.h>
#include <stdlib.h>
#include <glpk.h>

int main(void)
{       glp_prob *lp;
        int ia[1+1000], ja[1+1000];
        double x3, x6;
        double ar[1+1000], z, x1, x2, x4, x5;
        lp = glp_create_prob();
        glp_set_prob_name(lp, "provaglpk");
        glp_set_obj_dir(lp, GLP_MIN);           
        glp_add_rows(lp, 1);
        glp_set_row_name(lp, 1, "p");
        glp_set_row_bnds(lp, 1, GLP_FX, 600, 0.0);
        glp_add_cols(lp, 6);
        glp_set_col_name(lp, 1, "x1");
        glp_set_col_bnds(lp, 1, GLP_DB, 0, 240);
        glp_set_obj_coef(lp, 1, 0.18);
        glp_set_col_name(lp, 2, "x2");
        glp_set_col_bnds(lp, 2, GLP_DB, 0, 480);
        glp_set_obj_coef(lp, 2, 0.17);

        glp_set_col_name(lp, 3, "x3");
        glp_set_col_bnds(lp, 3, GLP_DB, 0.0, 1.0);
        glp_set_col_kind(lp, 3, GLP_IV);
        glp_set_obj_coef(lp, 3, 0.2);

        glp_set_col_name(lp, 4, "x4");
        glp_set_col_bnds(lp, 4, GLP_DB, 0, 240);
        glp_set_obj_coef(lp, 4, 0.18);
        glp_set_col_name(lp, 5, "x5");
        glp_set_col_bnds(lp, 5, GLP_DB, 0, 480);
        glp_set_obj_coef(lp, 5, 0.17);
        glp_set_col_name(lp, 6, "x6");
        glp_set_col_bnds(lp, 6, GLP_DB, 0, 1);
        glp_set_col_kind(lp, 6, GLP_BV);
        glp_set_obj_coef(lp, 6, 0.2);
        ia[1] = 1, ja[1] = 1, ar[1] = 1.0; 
        ia[2] = 1, ja[2] = 2, ar[2] = 1.0;
        ia[3] = 1, ja[3] = 3, ar[3] = 48;
        ia[4] = 1, ja[4] = 4, ar[4] = 1;
        ia[5] = 1, ja[5] = 5, ar[5] = 1;
        ia[6] = 1, ja[6] = 6, ar[6] = 48;
        glp_load_matrix(lp, 6, ia, ja, ar);
        int status;
        status = glp_simplex(lp, NULL);
        status = glp_intopt(lp, NULL);
        z = glp_get_obj_val(lp);
        x1 = glp_mip_col_val(lp, 1);
        x2 = glp_mip_col_val(lp, 2);
        x3 = glp_mip_col_val(lp, 3);
        x4 = glp_mip_col_val(lp, 4);
        x5 = glp_mip_col_val(lp, 5);
        x6 = glp_mip_col_val(lp, 6);
        printf("\nz = %f; x1 = %f; x2 = %f; x3 = %f; x4 = %f; x5 = %f; x6 =
%f\n",z, x1, x2, x3, x4, x5 ,x6);
        glp_delete_prob(lp);
        system("pause");
        return 0;
        }
/* eof */

Tihs is a more complex problem.

The solution that i need is like this.

Do you help me?

Thanks again! =)
-- 
View this message in context: 
http://old.nabble.com/Help%3A-How-to-build-MIP-model-tp34858053p34858521.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]