From: Mikko Rasa Date: Wed, 29 May 2013 19:12:11 +0000 (+0300) Subject: The entire row should be divided when initially making a column basic X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b15a68afd1d1c36cb953bc29bf234413991c911d;p=libs%2Fgltk.git The entire row should be divided when initially making a column basic Failing to do so will alter the row's meaning if the nonzero value in the column is anything else than 1.0. --- diff --git a/source/layout.cpp b/source/layout.cpp index d3d015f..ba726f7 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -497,11 +497,12 @@ void Layout::LinearProgram::prepare_columns() /* See if any variables are already basic. A basic variable must only have a nonzero coefficient on one row, and its product with the constant column must not be negative. Only one variable can be basic for any given row. */ - vector basic_coeff(n_rows, 0.0f); + vector obj_coeff(n_rows, 0.0f); + vector row_coeff(n_rows, 1.0f); const vector &constants = columns.back().values; for(vector::iterator i=columns.begin(); i!=columns.end(); ++i) { - if(i->values.size()>=2 && i->values.back()!=0.0f && (constants.size()values.size() || i->values.back()*constants[i->values.size()-1]>=0.0f) && basic_coeff[i->values.size()-1]==0.0f) + if(i->values.size()>=2 && i->values.back()!=0.0f && (constants.size()values.size() || i->values.back()*constants[i->values.size()-1]>=0.0f) && obj_coeff[i->values.size()-1]==0.0f) { bool basic = true; for(unsigned j=1; (basic && j+1values.size()); ++j) @@ -509,7 +510,8 @@ void Layout::LinearProgram::prepare_columns() if(basic) { i->basic = i->values.size()-1; - basic_coeff[i->basic] = -i->values.front()/i->values.back(); + row_coeff[i->basic] = 1.0f/i->values.back(); + obj_coeff[i->basic] = -i->values.front(); i->values.clear(); } } @@ -520,7 +522,10 @@ void Layout::LinearProgram::prepare_columns() if(!i->values.empty()) { for(unsigned j=0; jvalues.size(); ++j) - i->values.front() += basic_coeff[j]*i->values[j]; + { + i->values[j] *= row_coeff[j]; + i->values.front() += obj_coeff[j]*i->values[j]; + } } }