/* Add an edit variable to the solver. This method should be called before the `suggestValue` method is used to supply a suggested value for the given edit variable. Throws ------ DuplicateEditVariable The given edit variable has already been added to the solver. BadRequiredStrength The given strength is >= required. */ public void addEditVariable( Variable variable, double strength ) { if(m_edits.ContainsKey(variable)) throw new System.ArgumentException("DuplicateEditVariable", "SolverImpl"); strength = Strength.clip( strength ); if( strength == Strength.required ) throw new System.ArgumentException("BadRequiredStrength", "SolverImpl");//BadRequiredStrength(); Constraint cn = new Constraint(new Expression( variable ), RelationalOperator.OP_EQ, strength ); addConstraint( cn ); EditInfo info=new EditInfo(); info.tag = m_cns[ cn ]; info.constraint = cn; info.constant = 0.0; m_edits[ variable ] = info; }
/* Suggest a value for the given edit variable. This method should be used after an edit variable as been added to the solver in order to suggest the value for that variable. Throws ------ UnknownEditVariable The given edit variable has not been added to the solver. */ public void suggestValue( Variable variable, double value ) { if(!m_edits.ContainsKey(variable)) throw new System.ArgumentException("UnknownEditVariable", "SolverImpl"); //DualOptimizeGuard guard( *this ); EditInfo info = m_edits[variable]; double delta = value - info.constant; info.constant = value; // Check first if the positive error variable is basic. Row trial; if( m_rows.TryGetValue(info.tag.marker,out trial) ) { if( trial.add( -delta ) < 0.0 ) m_infeasible_rows.Add(info.tag.marker ); dualOptimize(); return; } // Check next if the negative error variable is basic. if( m_rows.TryGetValue(info.tag.other,out trial) ) { if( trial.add( delta ) < 0.0 ) m_infeasible_rows.Add( info.tag.other ); dualOptimize(); return; } // Otherwise update each row where the error variables exist. foreach(KeyValuePair<Symbol,Row> r in m_rows) { double coeff = r.Value.coefficientFor( info.tag.marker ); if( coeff != 0.0 && r.Value.add( delta * coeff ) < 0.0 && r.Key.type() != Symbol.Type.External ) m_infeasible_rows.Add(r.Key ); } dualOptimize(); }