/* * Produce a debugging string describing an NValue. */ std::string NValue::debug() const { const ValueType type = getValueType(); if (isNull()) { return "<NULL>"; } std::ostringstream buffer; std::string out_val; const char* ptr; int64_t addr; buffer << getTypeName(type) << "::"; switch (type) { case VALUE_TYPE_TINYINT: buffer << static_cast<int32_t>(getTinyInt()); break; case VALUE_TYPE_SMALLINT: buffer << getSmallInt(); break; case VALUE_TYPE_INTEGER: buffer << getInteger(); break; case VALUE_TYPE_BIGINT: case VALUE_TYPE_TIMESTAMP: buffer << getBigInt(); break; case VALUE_TYPE_DOUBLE: buffer << getDouble(); break; case VALUE_TYPE_VARCHAR: ptr = reinterpret_cast<const char*>(getObjectValue()); addr = reinterpret_cast<int64_t>(ptr); out_val = std::string(ptr, getObjectLength()); buffer << "[" << getObjectLength() << "]"; buffer << "\"" << out_val << "\"[@" << addr << "]"; break; case VALUE_TYPE_VARBINARY: ptr = reinterpret_cast<const char*>(getObjectValue()); addr = reinterpret_cast<int64_t>(ptr); out_val = std::string(ptr, getObjectLength()); buffer << "[" << getObjectLength() << "]"; buffer << "-bin[@" << addr << "]"; break; case VALUE_TYPE_DECIMAL: buffer << createStringFromDecimal(); break; default: buffer << getTypeName(type); } std::string ret(buffer.str()); return (ret); }
NValue NValue::itemAtIndex(int index) const { assert(m_valueType == VALUE_TYPE_ARRAY); NValueList* listOfNValues = (NValueList*)getObjectValue(); assert(index >= 0); assert(index < listOfNValues->m_length); return listOfNValues->m_values[index]; }
void NValue::setArrayElements(std::vector<NValue> &args) const { assert(m_valueType == VALUE_TYPE_ARRAY); NValueList* listOfNValues = (NValueList*)getObjectValue(); // Assign each of the elements. int ii = (int)args.size(); assert(ii == listOfNValues->m_length); while (ii--) { listOfNValues->m_values[ii] = args[ii]; } //TODO: An O(ln(length)) implementation vs. the current O(length) implementation of NValue::inList // would likely require some kind of sorting/re-org of values at this point post-update pre-lookup. }
void Tableau::pivot(size_t pivotRow, size_t pivotColumn, bool primalSimplex) { TableauRow &row = m_table[pivotRow]; const int leaveBasis = row.m_basisVariable; const int enterBasis = (int)pivotColumn; row.m_basisVariable = (int)pivotColumn; const Real &factor = row.m_a[pivotColumn]; const String enteringVarName = getVariableName(enterBasis); const String leavingVarName = getVariableName(leaveBasis); if(isTracing(TRACE_PIVOTING)) { if(primalSimplex) { trace(_T("pivot(%2s,%2s). %s -> %s. Cost[%s]:%-15.10lg Tab[%2s,%2s]=%-15.10lg Minimum:%-15.10lg") ,FSZ(pivotRow),FSZ(pivotColumn) ,enteringVarName.cstr(),leavingVarName.cstr() ,enteringVarName.cstr(),getDouble(getObjectFactor(pivotColumn)) ,FSZ(pivotRow),FSZ(pivotColumn),getDouble(factor) ,getDouble(getObjectValue())); } else { trace(_T("pivot(%2s,%2s). %s -> %s. %s=B[%2s]:%-15.10lg Tab[%2s,%2s]=%-15.10lg Minimum:%-15.10lg") ,FSZ(pivotRow),FSZ(pivotColumn) ,enteringVarName.cstr(),leavingVarName.cstr() ,leavingVarName.cstr(),FSZ(pivotRow),getDouble(getRightSide(pivotRow)) ,FSZ(pivotRow),FSZ(pivotColumn),getDouble(factor) ,getDouble(getObjectValue())); } } multiplyRow(pivotRow,1.0/factor); for(int dstRow = 0; dstRow <= getConstraintCount(); dstRow++) { if(dstRow != (int)pivotRow) { addRowsToGetZero(dstRow,pivotRow,pivotColumn); } } }
String Tableau::toString(int fieldSize, int decimals) const { const String matrixFormatString = format(_T("%%%d.%dlg "), fieldSize, decimals); const TCHAR *matrixFormat = matrixFormatString.cstr(); const int width = getWidth(); const int constraintCount = getConstraintCount(); #define NEWLINE _T('\n') const String separatorLine = format(_T("%s\n"), spaceString(12 + (width+1) * (fieldSize+1) + 3,_T('_')).cstr()); String result; result += format(_T("%-23sB %-*s"), format(_T("size:%dx%d"),getConstraintCount(),getWidth()).cstr(),fieldSize-8,EMPTYSTRING); for(int col = 1; col <= width; col++) { result += format(_T("%*s "), fieldSize, getVariableName(col).cstr()); } result += NEWLINE; result += separatorLine; result += format(_T("%-*s"), 17+fieldSize, _T("Orig. cost: ")); for(int col = 1; col <= getXCount(); col++) { result += format(matrixFormat, getDouble(m_costFactor[col])); } result += NEWLINE; result += _T("ObjectValue:"); result += format(matrixFormat, getDouble(getObjectValue())); result += _T(" "); // filler instead of relation for(int col = 1; col <= width; col++) { result += format(matrixFormat, getDouble(getObjectFactor(col))); } result += NEWLINE; result += separatorLine; const bool printOriginalRelation = (m_slackCount == 0); for(int r = 1; r <= constraintCount; r++ ) { const TableauRow &row = m_table[r]; result += format(_T("%3d %-6s ="),r, getVariableName(row.m_basisVariable).cstr()); result += format(matrixFormat,getDouble(getRightSide(r))); result += format(_T(" %-2s "), printOriginalRelation ? getRelationString(reverseRelation(row.m_relation)) : _T("=")); for(int col = 1; col <= width; col++) { result += format(matrixFormat,getDouble(row.m_a[col])); } result += NEWLINE; } return result; }
std::string StringPlug::getValue() const { IECore::ConstObjectPtr o = getObjectValue(); const IECore::StringData *s = IECore::runTimeCast<const IECore::StringData>( o.get() ); if( !s ) { throw IECore::Exception( "StringPlug::getObjectValue() didn't return StringData - is the hash being computed correctly?" ); } bool performSubstitution = direction()==Plug::In && inCompute() && Plug::getFlags( Plug::PerformsSubstitutions ) && Context::hasSubstitutions( s->readable() ); return performSubstitution ? Context::current()->substitute( s->readable() ) : s->readable(); }
IECore::MurmurHash StringPlug::hash() const { bool performSubstitution = direction()==Plug::In && !getInput<ValuePlug>() && Plug::getFlags( Plug::PerformsSubstitutions ); if( performSubstitution ) { IECore::ConstObjectPtr o = getObjectValue(); const IECore::StringData *s = IECore::runTimeCast<const IECore::StringData>( o.get() ); if( !s ) { throw IECore::Exception( "StringPlug::getObjectValue() didn't return StringData - is the hash being computed correctly?" ); } if( Context::hasSubstitutions( s->readable() ) ) { IECore::MurmurHash result; result.append( Context::current()->substitute( s->readable() ) ); return result; } } // no substitutions return ValuePlug::hash(); }
SimplexSolution Tableau::getSolution() const { return SimplexSolution(getBasisVariables(),getObjectValue()); }
int NValue::arrayLength() const { assert(m_valueType == VALUE_TYPE_ARRAY); NValueList* listOfNValues = (NValueList*)getObjectValue(); return static_cast<int>(listOfNValues->m_length); }