_copyLp(), _newLp() implemented.
1.1 --- a/lemon/lp_base.h Mon May 23 04:48:14 2005 +0000
1.2 +++ b/lemon/lp_base.h Thu May 26 12:16:16 2005 +0000
1.3 @@ -417,7 +417,14 @@
1.4
1.5 //Abstract virtual functions
1.6 virtual LpSolverBase &_newLp() = 0;
1.7 - virtual LpSolverBase &_copyLp() = 0;
1.8 + virtual LpSolverBase &_copyLp(){
1.9 + ///\todo This should be implemented here, too, when we have problem retrieving routines. It can be overriden.
1.10 +
1.11 + //Starting:
1.12 + LpSolverBase & newlp(_newLp());
1.13 + return newlp;
1.14 + //return *(LpSolverBase*)0;
1.15 + };
1.16
1.17 virtual int _addCol() = 0;
1.18 virtual int _addRow() = 0;
1.19 @@ -608,6 +615,15 @@
1.20 return r;
1.21 }
1.22
1.23 + ///Set an element of the coefficient matrix of the LP
1.24 +
1.25 + ///\param r is the row of the element to be modified
1.26 + ///\param c is the coloumn of the element to be modified
1.27 + ///\param val is the new value of the coefficient
1.28 + void setCoeff(Row r, Col c, Value val){
1.29 + _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
1.30 + }
1.31 +
1.32 /// Set the lower bound of a column (i.e a variable)
1.33
1.34 /// The upper bound of a variable (column) has to be given by an
2.1 --- a/lemon/lp_cplex.cc Mon May 23 04:48:14 2005 +0000
2.2 +++ b/lemon/lp_cplex.cc Thu May 26 12:16:16 2005 +0000
2.3 @@ -21,56 +21,33 @@
2.4 namespace lemon {
2.5
2.6 LpCplex::LpCplex() : LpSolverBase() {
2.7 - env = NULL;
2.8 - lp = NULL;
2.9 - env = CPXopenCPLEXdevelop(&status);
2.10 -// if (Env == NULL)
2.11 -// {
2.12 -// fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
2.13 -// CPXgeterrorstring(Env, Status, ErrorMsg);
2.14 -// fprintf(stderr,"%s",ErrorMsg);
2.15 -// goto Terminate;
2.16 -// }
2.17 -
2.18 - // *** A problema létrehozása ***
2.19 +
2.20 + // env = CPXopenCPLEXdevelop(&status);
2.21 + env = CPXopenCPLEX(&status);
2.22 lp = CPXcreateprob(env, &status, "LP problem");
2.23 -
2.24 - // if (Problem == NULL)
2.25 -// {
2.26 -// fprintf(stderr,"Az LP létrehozása sikertelen");
2.27 -// goto Terminate;
2.28 -// }
2.29 -
2.30 + //CPXmsg (cpxresults, "Hello-bello\n");
2.31 }
2.32
2.33 LpCplex::~LpCplex() {
2.34 - status = CPXfreeprob(env,&lp);
2.35 - // if (Status != 0)
2.36 - // {
2.37 -// fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
2.38 -// CPXgeterrorstring(Env, Status, ErrorMsg);
2.39 -// fprintf(stderr,"%s",ErrorMsg);
2.40 -// goto Terminate;
2.41 -// }
2.42 -
2.43 - status = CPXcloseCPLEX(&env);
2.44 - // if (Status != 0)
2.45 - // {
2.46 - // fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
2.47 -// CPXgeterrorstring(Env, Status, ErrorMsg);
2.48 -// fprintf(stderr,"%s",ErrorMsg);
2.49 -// goto Terminate;
2.50 -// }
2.51 -
2.52 + CPXfreeprob(env,&lp);
2.53 + CPXcloseCPLEX(&env);
2.54 }
2.55
2.56 LpSolverBase &LpCplex::_newLp()
2.57 {
2.58 - return *(LpSolverBase*)0;
2.59 + //The first approach opens a new environment
2.60 + LpCplex* newlp=new LpCplex();
2.61 + return *newlp;
2.62 }
2.63 +
2.64 LpSolverBase &LpCplex::_copyLp() {
2.65 - return *(LpSolverBase*)0;
2.66 - //Ez lesz majd CPXcloneprob (env, lp, &status);
2.67 + //The first approach opens a new environment
2.68 + LpCplex* newlp=new LpCplex();
2.69 + //The routine CPXcloneprob can be used to create a new CPLEX problem
2.70 + //object and copy all the problem data from an existing problem
2.71 + //object to it. Solution and starting information is not copied.
2.72 + newlp->lp = CPXcloneprob (env, lp, &status);
2.73 + return *newlp;
2.74 }
2.75
2.76 int LpCplex::_addCol()
2.77 @@ -82,6 +59,7 @@
2.78 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
2.79 return i;
2.80 }
2.81 +
2.82
2.83 int LpCplex::_addRow()
2.84 {
2.85 @@ -97,11 +75,11 @@
2.86
2.87
2.88 void LpCplex::_eraseCol(int i) {
2.89 - ///\todo Not implemented yet
2.90 + CPXdelcols (env, lp, i, i);
2.91 }
2.92
2.93 void LpCplex::_eraseRow(int i) {
2.94 - ///\todo Not implemented yet
2.95 + CPXdelrows (env, lp, i, i);
2.96 }
2.97
2.98
3.1 --- a/lemon/lp_glpk.cc Mon May 23 04:48:14 2005 +0000
3.2 +++ b/lemon/lp_glpk.cc Thu May 26 12:16:16 2005 +0000
3.3 @@ -24,25 +24,6 @@
3.4
3.5 namespace lemon {
3.6
3.7 - ///\e
3.8 -
3.9 - ///\bug Unimplemented!
3.10 - ///
3.11 - LpSolverBase &LpGlpk::_newLp()
3.12 - {
3.13 - LpSolverBase *tmp=0;
3.14 - return *tmp;
3.15 - }
3.16 -
3.17 - ///\e
3.18 -
3.19 - ///\bug Unimplemented!
3.20 - ///
3.21 - LpSolverBase &LpGlpk::_copyLp()
3.22 - {
3.23 - LpSolverBase *tmp=0;
3.24 - return *tmp;
3.25 - }
3.26
3.27 LpGlpk::LpGlpk() : Parent(),
3.28 lp(lpx_create_prob()) {
3.29 @@ -62,6 +43,49 @@
3.30 return i;
3.31 }
3.32
3.33 + ///\e
3.34 +
3.35 +
3.36 + LpSolverBase &LpGlpk::_newLp()
3.37 + {
3.38 + LpGlpk* newlp=new LpGlpk();
3.39 + return *newlp;
3.40 + }
3.41 +
3.42 + ///\e
3.43 +
3.44 + LpSolverBase &LpGlpk::_copyLp()
3.45 + {
3.46 + LpGlpk* newlp=new LpGlpk();
3.47 +
3.48 + //Coefficient matrix, row bounds
3.49 + lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
3.50 + lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
3.51 + int len;
3.52 + int ind[1+lpx_get_num_cols(lp)];
3.53 + Value val[1+lpx_get_num_cols(lp)];
3.54 + for (int i=1;i<=lpx_get_num_rows(lp);++i){
3.55 + len=lpx_get_mat_row(lp,i,ind,val);
3.56 + lpx_set_mat_row(newlp->lp, i,len,ind,val);
3.57 + lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
3.58 + lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
3.59 + }
3.60 +
3.61 + //Objective function, coloumn bounds
3.62 + lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
3.63 + //Objectif function's constant term treated separately
3.64 + lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
3.65 + for (int i=1;i<=lpx_get_num_cols(lp);++i){
3.66 + lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
3.67 + lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
3.68 + lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
3.69 +
3.70 +
3.71 + }
3.72 +
3.73 + return *newlp;
3.74 + }
3.75 +
3.76 int LpGlpk::_addRow() {
3.77 int i=lpx_add_rows(lp, 1);
3.78 return i;