int glp_read_ipt(glp_prob *lp, const char *fname)
{   glp_data *data;
    jmp_buf jump;
    int i, j, k, ret = 0;
    xprintf("Reading interior-point solution from '%s'...\n", fname);
    data = glp_sdf_open_file(fname);
    if (data == NULL)
    {   ret = 1;
        goto done;
    }
    if (setjmp(jump))
    {   ret = 1;
        goto done;
    }
    glp_sdf_set_jump(data, jump);
    /* number of rows, number of columns */
    k = glp_sdf_read_int(data);
    if (k != lp->m)
        glp_sdf_error(data, "wrong number of rows\n");
    k = glp_sdf_read_int(data);
    if (k != lp->n)
        glp_sdf_error(data, "wrong number of columns\n");
    /* solution status, objective value */
    k = glp_sdf_read_int(data);
    if (!(k == GLP_UNDEF || k == GLP_OPT))
        glp_sdf_error(data, "invalid solution status\n");
    lp->ipt_stat = k;
    lp->ipt_obj = glp_sdf_read_num(data);
    /* rows (auxiliary variables) */
    for (i = 1; i <= lp->m; i++)
    {   GLPROW *row = lp->row[i];
        /* primal value, dual value */
        row->pval = glp_sdf_read_num(data);
        row->dval = glp_sdf_read_num(data);
    }
    /* columns (structural variables) */
    for (j = 1; j <= lp->n; j++)
    {   GLPCOL *col = lp->col[j];
        /* primal value, dual value */
        col->pval = glp_sdf_read_num(data);
        col->dval = glp_sdf_read_num(data);
    }
    xprintf("%d lines were read\n", glp_sdf_line(data));
done:
    if (ret) lp->ipt_stat = GLP_UNDEF;
    if (data != NULL) glp_sdf_close_file(data);
    return ret;
}
int glp_read_mip(glp_prob *mip, const char *fname)
{   glp_data *data;
    jmp_buf jump;
    int i, j, k, ret = 0;
    xprintf("Reading MIP solution from '%s'...\n", fname);
    data = glp_sdf_open_file(fname);
    if (data == NULL)
    {   ret = 1;
        goto done;
    }
    if (setjmp(jump))
    {   ret = 1;
        goto done;
    }
    glp_sdf_set_jump(data, jump);
    /* number of rows, number of columns */
    k = glp_sdf_read_int(data);
    if (k != mip->m)
        glp_sdf_error(data, "wrong number of rows\n");
    k = glp_sdf_read_int(data);
    if (k != mip->n)
        glp_sdf_error(data, "wrong number of columns\n");
    /* solution status, objective value */
    k = glp_sdf_read_int(data);
    if (!(k == GLP_UNDEF || k == GLP_OPT || k == GLP_FEAS ||
            k == GLP_NOFEAS))
        glp_sdf_error(data, "invalid solution status\n");
    mip->mip_stat = k;
    mip->mip_obj = glp_sdf_read_num(data);
    /* rows (auxiliary variables) */
    for (i = 1; i <= mip->m; i++)
    {   GLPROW *row = mip->row[i];
        row->mipx = glp_sdf_read_num(data);
    }
    /* columns (structural variables) */
    for (j = 1; j <= mip->n; j++)
    {   GLPCOL *col = mip->col[j];
        col->mipx = glp_sdf_read_num(data);
        if (col->kind == GLP_IV && col->mipx != floor(col->mipx))
            glp_sdf_error(data, "non-integer column value");
    }
    xprintf("%d lines were read\n", glp_sdf_line(data));
done:
    if (ret) mip->mip_stat = GLP_UNDEF;
    if (data != NULL) glp_sdf_close_file(data);
    return ret;
}
Beispiel #3
0
int glp_read_graph(glp_graph *G, const char *fname)
{   glp_data *data;
    jmp_buf jump;
    int nv, na, i, j, k, ret;
    glp_erase_graph(G, G->v_size, G->a_size);
    xprintf("Reading graph from `%s'...\n", fname);
    data = glp_sdf_open_file(fname);
    if (data == NULL)
    {   ret = 1;
        goto done;
    }
    if (setjmp(jump))
    {   ret = 1;
        goto done;
    }
    glp_sdf_set_jump(data, jump);
    nv = glp_sdf_read_int(data);
    if (nv < 0)
        glp_sdf_error(data, "invalid number of vertices\n");
    na = glp_sdf_read_int(data);
    if (na < 0)
        glp_sdf_error(data, "invalid number of arcs\n");
    xprintf("Graph has %d vert%s and %d arc%s\n",
            nv, nv == 1 ? "ex" : "ices", na, na == 1 ? "" : "s");
    if (nv > 0) glp_add_vertices(G, nv);
    for (k = 1; k <= na; k++)
    {   i = glp_sdf_read_int(data);
        if (!(1 <= i && i <= nv))
            glp_sdf_error(data, "tail vertex number out of range\n");
        j = glp_sdf_read_int(data);
        if (!(1 <= j && j <= nv))
            glp_sdf_error(data, "head vertex number out of range\n");
        glp_add_arc(G, i, j);
    }
    xprintf("%d lines were read\n", glp_sdf_line(data));
    ret = 0;
done:
    if (data != NULL) glp_sdf_close_file(data);
    return ret;
}
int glp_read_sol(glp_prob *lp, const char *fname)
{   glp_data *data;
    jmp_buf jump;
    int i, j, k, ret = 0;
    xprintf("Reading basic solution from '%s'...\n", fname);
    data = glp_sdf_open_file(fname);
    if (data == NULL)
    {   ret = 1;
        goto done;
    }
    if (setjmp(jump))
    {   ret = 1;
        goto done;
    }
    glp_sdf_set_jump(data, jump);
    /* number of rows, number of columns */
    k = glp_sdf_read_int(data);
    if (k != lp->m)
        glp_sdf_error(data, "wrong number of rows\n");
    k = glp_sdf_read_int(data);
    if (k != lp->n)
        glp_sdf_error(data, "wrong number of columns\n");
    /* primal status, dual status, objective value */
    k = glp_sdf_read_int(data);
    if (!(k == GLP_UNDEF || k == GLP_FEAS || k == GLP_INFEAS ||
            k == GLP_NOFEAS))
        glp_sdf_error(data, "invalid primal status\n");
    lp->pbs_stat = k;
    k = glp_sdf_read_int(data);
    if (!(k == GLP_UNDEF || k == GLP_FEAS || k == GLP_INFEAS ||
            k == GLP_NOFEAS))
        glp_sdf_error(data, "invalid dual status\n");
    lp->dbs_stat = k;
    lp->obj_val = glp_sdf_read_num(data);
    /* rows (auxiliary variables) */
    for (i = 1; i <= lp->m; i++)
    {   GLPROW *row = lp->row[i];
        /* status, primal value, dual value */
        k = glp_sdf_read_int(data);
        if (!(k == GLP_BS || k == GLP_NL || k == GLP_NU ||
                k == GLP_NF || k == GLP_NS))
            glp_sdf_error(data, "invalid row status\n");
        glp_set_row_stat(lp, i, k);
        row->prim = glp_sdf_read_num(data);
        row->dual = glp_sdf_read_num(data);
    }
    /* columns (structural variables) */
    for (j = 1; j <= lp->n; j++)
    {   GLPCOL *col = lp->col[j];
        /* status, primal value, dual value */
        k = glp_sdf_read_int(data);
        if (!(k == GLP_BS || k == GLP_NL || k == GLP_NU ||
                k == GLP_NF || k == GLP_NS))
            glp_sdf_error(data, "invalid column status\n");
        glp_set_col_stat(lp, j, k);
        col->prim = glp_sdf_read_num(data);
        col->dual = glp_sdf_read_num(data);
    }
    xprintf("%d lines were read\n", glp_sdf_line(data));
done:
    if (ret) lp->pbs_stat = lp->dbs_stat = GLP_UNDEF;
    if (data != NULL) glp_sdf_close_file(data);
    return ret;
}