[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] [Fwd: duplicate indices problem]
From: |
Andrew Makhorin |
Subject: |
[Help-glpk] [Fwd: duplicate indices problem] |
Date: |
Wed, 20 Jun 2018 16:11:06 +0300 |
-------- Forwarded Message --------
From: Karol Rydzewski <address@hidden>
To: address@hidden
Subject: duplicate indices problem
Date: Tue, 19 Jun 2018 23:48:01 +0200
Hi,
I have a problem with using glpk library in my solution. I am getting an
error when running glp_load_matrix(problem, filled-1, X, Y, coeff)
saying: "glp_load_mat: ia[1] = 1; ja[1] = 3; duplicate indices not
allowed
Error detected in file glpapi01.c at line 1032" However, I cannot get an
idea on what I am doing wrong and I cannot find any clue anywhere.
Please advice me how to get it working. My piece of code resulting in
this is:
unsigned i,j, k, filled;
int *X,*Y;
double *pathPerf, *coeff;
glp_smcp smcp;
glp_init_smcp(&smcp);
smcp.msg_lev=GLP_MSG_DBG;
//glp problem structure
glp_prob *problem;
problem=glp_create_prob();
//allocate memory for coeff data
X=(int*)malloc(sizeof(int)*(pathsNo+1));
Y=(int*)malloc(sizeof(int)*(nodesNo+1));
coeff=(double*)malloc(sizeof(double)*(nodesNo+1));
//define number of rows and columns in the problem matrix
glp_add_rows(problem, pathsNo);
glp_add_cols(problem, nodesNo);
//seting column's bounds
for(i=1;i<=nodesNo;i++)
glp_set_col_bnds(problem,i,GLP_LO,0.0,0);
//right-hand values of each equation
for(i=1;i<=pathsNo;i++)
{
glp_set_row_bnds(problem,i,PathsTab[i-1].performance,0);
}
filled=1;
for(i=1;i<=pathsNo;i++)
{
for(j=1;j<=PathsTab[i-1].length;j++)
{
printf("%d:%d ",i,PathsTab[i-1].nodes[j-1]);
X[filled]=i,Y[filled]=PathsTab[i-1].nodes[j-1],coeff[filled]=1.0;
filled++;
}
printf("\n");
}
for(i=1;i<nodesNo;i++)
glp_set_obj_coef(problem, i, 0.0);
glp_set_obj_dir(problem, GLP_MIN);
for(unsigned j=1;j<=nodesNo;j++)
{
glp_set_obj_coef(problem, j, 1.0);
glp_load_matrix(problem, filled-1, X, Y, coeff);
glp_simplex(problem, &smcp);
NodesTab[j-1].trustWrth[1]=glp_get_col_prim(problem,j);
glp_set_obj_coef(problem,j, 0.0);
}
And the output I get is:
1:12 1:2 1:18 1:5
2:14 2:18 2:19
3:10 3:20 3:12
glp_load_mat: ia[1] = 1; ja[1] = 3; duplicate indices not
allowed
Error detected in file glpapi01.c at line 1032
Aborted (core dumped)
Thank you,
Karol
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-glpk] [Fwd: duplicate indices problem],
Andrew Makhorin <=