Skip to main content

converst string (constraint) into GRBLinExpr (C++)

Comments

3 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    I'm not sure I understand your question well. Can you provide an example of a string that you want to convert into a linear expression?

    0
  • zakarya guettatfi
    Gurobi-versary
    Curious
    First Comment

    Thank you for your reply, I have an old work with lp_solve, and I want to use gurobi API C++ : all my constraints written as string to a file, so I am looking for putting my string constraints equations to the model.

    I try to do somthing like that (put a string to constraint) :

    sprintf(Constraint1, "x%d + %d r%d - %d r%d - x%d - %d p%d%d - %d q%d%d <= - %d\n", i, hi, i, wi, i, j, M, i, j, M, i, j, wi);

    model.addConstr(Constraint1);

    My Old code :

    ------------------------------------------------

    for (int i = 1; i <= block_list->size(); i++) {
    for (int j = i + 1; j <= block_list->size(); j++) {
    hi = block_list->at(i - 1)->height;
    hj = block_list->at(j - 1)->height;
    wi = block_list->at(i - 1)->width;
    wj = block_list->at(j - 1)->width;
    fprintf(f, "c%d: x%d + %d r%d - %d r%d - x%d - %d p%d%d - %d q%d%d <= - %d\n", eq++, i, hi, i, wi, i, j, M, i, j, M, i, j, wi);
    fprintf(f, "c%d: y%d + %d r%d - %d r%d - y%d - %d p%d%d + %d q%d%d <= + %d\n", eq++, i, wi, i, hi, i, j, M, i, j, M, i, j, M-hi);
    fprintf(f, "c%d: x%d - %d r%d + %d r%d - x%d - %d p%d%d + %d q%d%d >= - %d\n ", eq++, i, hj, j, wj, j, j, M, i, j, M, i, j,M-wj);
    fprintf(f, "c%d: y%d - %d r%d + %d r%d - y%d - %d p%d%d - %d q%d%d >= - %d\n", eq++, i, wj, j, hj, j, j, M, i, j, M, i, j,(2 * M)-hj);
    //fprintf(f, "\n");
    }
    }

    0

Post is closed for comments.