help-glpk
[Top][All Lists]
Advanced

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

[Help-glpk] [Fwd: Calling the same LP repeatedly - segmentation fault]


From: Andrew Makhorin
Subject: [Help-glpk] [Fwd: Calling the same LP repeatedly - segmentation fault]
Date: Thu, 05 May 2016 21:11:37 +0300

-------- Forwarded Message --------
From: Kadiyala, Krishna <address@hidden>
To: address@hidden <address@hidden>
Subject: Calling the same LP repeatedly - segmentation fault
Date: Thu, 5 May 2016 17:04:23 +0000

Hi,

 

I have a C program that calls on GLPK to solve an LP, gathers
information from the solution of that LP,  and if the conditions in the
C program are not met, has to re-run the LP with the same parameters
until a permissible solution is found. I am however running into
segmentation faults when I try to do this. Here is the seg fault cause
from gdb:

 

 

Program received signal SIGSEGV, Segmentation fault.

0x0000000000422b34 in _glp_get_env_ptr ()

Missing separate debuginfos, use: debuginfo-install
glibc-2.17-106.el7_2.4.x86_64

(gdb) where

#0  0x0000000000422b34 in _glp_get_env_ptr ()

#1  0x00000000004223a6 in dma (address@hidden "glp_alloc",

    address@hidden, address@hidden) at env/alloc.c:47

#2  0x000000000042267c in glp_alloc (address@hidden, address@hidden)

    at env/alloc.c:141

#3  0x0000000000405880 in glp_create_prob () at glpapi01.c:109

#4  0x0000000000402f2d in GAP ()

#5  0x0000000000402c74 in main ()

(gdb)

 

And here is my code(sorry but it’s big):

 

int GAP(int ingress_routers[], int borders[], int prefix[], int
advertising_routers[net][PREFIXES], int capacities[], double *maxlu)

{

printf("Entered GAP now\n");

    int i,index,j,e,k,pr,z,f;

int number, jobs;

int machines = MACHINES;

int ingress = INGRESS;

int prefixes = PREFIXES;

int egress_links = MACHINES;

FILE *fr;

int x,y,t,c;

int g = ingress*prefixes ;

int flows[g+1], pos[g+1],traffic_demand[g];

for(x=0;x<g+1;x++)

{

pos[x] = x;

//printf("pos[%d]: %d\n", x, pos[x]);

}

 

for(i=0;i<g+1;i++)

    {

        flows[i] = i;

    }

 

////////////This is where the LP problem is
created//////////////////////

glp_prob *lp;

glp_tran *tran;

int ret;

lp = glp_create_prob();

tran = glp_mpl_alloc_wksp();

ret = glp_mpl_read_model(tran, "LP.mod", 0);

ret = glp_mpl_generate(tran, NULL);

glp_mpl_build_prob(tran, lp);

glp_simplex(lp, NULL);

glp_print_sol(lp,"LP.txt");

 

int status = glp_get_status(lp);

if (status == 4)

{

printf("Infeasible problem. Please change input parameters and retry
\n");

return 1;

}

else

{

printf("Input to the problem is feasible, proceeding to solve LP...\n");

}

int noc = glp_get_num_cols(lp);

jobs = (noc/machines);

 

 

//printf("number of columns: %d, number of egress routers: %d, number of
flows: %d\n", noc, machines, jobs);

 

int xmachines = MACHINES+1;

int xjobs = JOBS+1;

float X[xmachines][xjobs];

 

for(i=0;i<machines+1;i++)

{

for(j=0;j<jobs+1;j++)

{

X[i][j] = 0.0;

}

}

 

for(j=0;j<jobs+1;j++)

{

X[0][j] = 0.0;

}

 

for(i=0;i<machines+1;i++)

{

X[i][0] = 0.0;

}

 

z = 0;

int flow = 0;

int last_flow;

 

for(x=0;x<ingress;x++)

{

//printf("ingress router is: %d\n", ingress_routers[x]);

for(y=0; y<prefixes; y++)

{

//printf("prefix is: %d\n", prefix[y]);

z = z+1;

for(k=1;k<machines+1;k++)

{

//printf("k is: %d, job is %d\n", k, z);

t = borders[k-1];

pr = prefix[y];

//printf("adv[%d][%d] is: %d\n", t,pr,advertising_routers[t][pr]);

if (advertising_routers[t][pr] == 1)

{

flow=flow+1;

//printf("column i am retrieving is: %d\n", flow);

X[k][z]= glp_get_col_prim(lp, flow);

//printf("X[%d][%d] is: %f\n", k,z,X[k][z]);

last_flow = flow;

}

 

else

{

X[k][z] = 0.0;

}

}

}

}

 

******************Until here, I collect parameters from the LP problem
and then attempt to delete/free it*************

glp_free(lp);

 

char line[80], buffer[1024];

 

int dem[g], pos_size;

x = 0;

fr = fopen ("traffic_demand.txt", "r");  /* open the file for reading */

 

fgets(buffer, 1024, fr);

while (!feof(fr) && x<g+1) 

        {

            // Read a line and parse it.

            fgets(buffer, 1024, fr);

            sscanf(buffer, "%d", &number);

traffic_demand[x] = number; // store the number in the next free array
slot  

//printf("traffic_demand[%d]: %d\n", x, traffic_demand[x]);

dem[x] = traffic_demand[x];

x++; // increment the array index 

}

 

fclose(fr);  /* close the file prior to exiting the routine */

f = 0;

t = 0; 

for (x=1; x<g;  x++)

                {

                                for (y=1 ; y<g; y++)

                                {

                                  if (traffic_demand[y+1] <
traffic_demand[y])

                                                { 

                              t = traffic_demand[y];

                                                traffic_demand[y] =
traffic_demand[y + 1];

                                                traffic_demand[y + 1] =
t;

                        f = pos[y];

                        pos[y] = pos[y+1];

                        pos[y+1] = f;

                        }

}

//printf("pos[%d] : %d\n", x, pos[x]);

}// for sorting jobs in order of increasing job size

z = g;

for(x=1;x<g+1;x++)

{

int c = pos[x];

//printf("dem[%d]: %d\n", c, dem[c]);

flows[z] = dem[c];

//printf("pos[%d] : %d, flows[%d]: %d\n", x, pos[x], z, flows[z]);

z--;

}

 

for(i=0;i<machines+1;i++)

{

for(t=0;t<jobs+1;t++)

{

j = pos[t];

//printf("j : %d\n", j);

}

}

 

int link;

double MLU;

printf("Calling biparttite now\n");

Bipartite(X, pos, dem, &link, &MLU);

int egg = borders[link-1];

printf("link with max load is :%d\n", egg);

printf("Max load is: %f, on link %d with capacity %d\n", MLU, egg,
capacities[egg]);

*maxlu = (double)MLU/capacities[egg] ;

 

return *maxlu;

 

} //End of C program. This C program is called in main.

 

 

Any help is much appreciated !

 

Thank you,

Krishna

 

PhD student at UT Dallas, Texas.

 

 







reply via email to

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