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: Jeffrey Kantor
Subject: Re: [Help-glpk] Help: How to build MIP model
Date: Fri, 4 Jan 2013 07:33:28 -0500

Hi Luca,

This problem can be solved by inspection. You were given

> minimize { sum[from i=1 to 96] of {c1*x1(i)+c2*x2(i)+c3*x3(i)} }
> with this constraints:
> x1(i)+x2(i)+x3(i)=c4(i)
> x1(i)+x3(i)=c5
> x1>=5
> 0<=x2<=1 binary
> 0<=x3<=1 binary
>
> where x1, x2, x3 and c4 are vectors of 96 elements. c1,c2,c3,c5 are
> contants.

Subtracting the second equality from the first equality gives

x2(i) = c4(i)-c5 

which tells us a couple of things.  First, because x2(i) is binary, not every
choice of parameters will lead to a feasible MIP solution. c4(i) must be
either c5 or c5 + 1. The second equality gives 

x1(i) = c5 - x3(i) >= 5

which tells us c5 >= 5 for feasible solutions for x1(i), and c5 >= 6 for nontrivial
solutions for x3(i). Assuming feasibility for x1(i) and x2(i), we can
substitute their solutions into the objective function

obj = C +  { sum[from i=1 to 96] of {(c3-c1)*x3(i)} }

where C is a constant that I'm too lazy to write out. So it comes down to the
values of (c3-c1). Provided c5 >= 6 then x3(i) = - sgn(c3-c1).

If you still want to write a solver for the problem you should be careful about
handling coefficients.

Jeff





On Fri, Jan 4, 2013 at 6:35 AM, lucacoopers <address@hidden> wrote:

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.


_______________________________________________
Help-glpk mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-glpk


reply via email to

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