XDEBUG_NOTIMPLEMENTED static Variant HHVM_FUNCTION(xdebug_start_trace, const Variant& traceFileVar, int64_t options /* = 0 */) { // Allowed to pass null. folly::StringPiece trace_file; if (traceFileVar.isString()) { // We're not constructing a new String, we're just using the one in // traceFileVar, so this is safe. trace_file = traceFileVar.toString().slice(); } // Initialize the profiler if it isn't already. if (!XDEBUG_GLOBAL(ProfilerAttached)) { attach_xdebug_profiler(); } // php5 xdebug returns false when tracing already started. auto profiler = xdebug_profiler(); if (profiler->isTracing()) { return false; } // Start tracing, then grab the current begin frame start_tracing(profiler, trace_file, options); profiler->beginFrame(nullptr); return HHVM_FN(xdebug_get_tracefile_name)(); }
void Tableau::traceDegeneracy(int pivotRow, int pivotColumn, const Real &minRatio) const { if(!isTracing(TRACE_WARNINGS)) { return; } const int constraintCount = getConstraintCount(); String traceString; TCHAR *delimiter = EMPTYSTRING; for(int r = 1; r <= constraintCount; r++) { if(r == pivotRow) { continue; } const TableauRow &row = m_table[r]; const Real &ar = row.m_a[pivotColumn]; if(ar > EPS) { const Real ratio = row.getRightSide() / ar; if(ratio == minRatio) { traceString += format(_T("%s%d"),delimiter,r); delimiter = _T(","); } } } if(traceString.length() > 0) { trace(_T("Degenerated rows:[%s]"),traceString.cstr()); } }
/** * @brief Member function <b>isLoggable</b> returns true if any corresponding bit in the line mask * matches a bit in the print mask, except LOG_TRACE which also requires isTracing() to be true. * * @return a <b>bool</b> of true if any corresponding bit in * the line mask matches a bit inthe print mask. */ bool isLoggable(PrintMask line_mask) { return line_mask == 0 // Always || ((line_mask & m_printMask & stk::LOG_TRACE) // LOG_TRACE? ? isTracing() // Yes, must be tracing // : (line_mask & m_printMask) != 0); // No, any matching bits : (line_mask & m_printMask) == line_mask); // No, all matching bits }
void Tableau::trace(int flag, _In_z_ _Printf_format_string_ TCHAR const * const format, ...) const { if(isTracing(flag)) { va_list argptr; va_start(argptr,format); vtrace(format,argptr); va_end(argptr); } }
static Variant HHVM_FUNCTION(xdebug_get_tracefile_name) { if (XDEBUG_GLOBAL(ProfilerAttached)) { auto profiler = xdebug_profiler(); if (profiler->isTracing()) { return profiler->getTracingFilename(); } } return false; }
void MDBLog::traceLn(uint32_t typeBits, const char *format, ...) { if (isTracing(typeBits)) { char buffer[1024] = ""; va_list args; va_start(args, format); vsprintf(buffer, format, args); va_end(args); traceLn(getColorForType(typeBits), typeBits, buffer); } }
void MDBLog::traceLn(AnsiColor color, uint32_t typeBits, char *message) { if (isTracing(typeBits)) { if (true) { char buffer[512] = ""; appendString(buffer, color, "%s", message); traceLn(buffer); } else { traceLn(message); } } }
void TraceSource::initTraceSource( SharedTraceTarget pTraceTargetInit, std::string nameInit) { assert(!pTraceTarget.get()); pTraceTarget = pTraceTargetInit; name = nameInit; if (isTracing()) { minimumLevel = pTraceTarget->getSourceTraceLevel(name); } else { minimumLevel = TRACE_OFF; } }
SimplexResult Tableau::dualSimplex() { const int constraintCount = getConstraintCount(); const int width = getWidth(); for(int iteration = 1;; iteration++) { if(isTracing(TRACE_ITERATIONS)) { trace(_T("Dual simplex. Iteration %d."), iteration); traceTableau(); // traceBasis(_T("Current basis:")); } int pivotRow; Real minR = 1; for(int row = 1; row <= constraintCount; row++) { // find pivot row if(getRightSide(row) < minR) { pivotRow = row; minR = getRightSide(row); } } if(minR >= 0) { // Every rightside is nonNegative return SIMPLEX_SOLUTION_OK; } int pivotColumn = -1; Real minRatio = 0; const CompactArray<Real> &tableRow = m_table[pivotRow].m_a; for(int col = 1; col <= width; col++) { // find pivot col const Real &a = tableRow[col]; if(a < 0) { Real ratio = -getObjectFactor(col)/a; if(pivotColumn == -1 || ratio < minRatio) { minRatio = ratio; pivotColumn = col; } } } // printf(_T("pivotColumn:%d\n"),pivotColumn); if(pivotColumn == -1) { return SIMPLEX_NO_SOLUTION; } pivot(pivotRow,pivotColumn,false); } }
XDEBUG_NOTIMPLEMENTED static Variant HHVM_FUNCTION(xdebug_stop_trace) { if (!XDEBUG_GLOBAL(ProfilerAttached)) { return false; } auto profiler = xdebug_profiler(); if (!profiler->isTracing()) { return false; } // End with xdebug_stop_trace() profiler->endFrame(init_null().asTypedValue(), nullptr, false); auto filename = profiler->getTracingFilename(); profiler->disableTracing(); detach_xdebug_profiler_if_needed(); return filename; }
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); } } }
void TraceSource::trace(TraceLevel level, std::string message) const { if (isTracing()) { getTraceTarget().notifyTrace(name, level, message); } }
/** * @brief Member function <b>isTraceable</b> returns true if currently tracing or * tracing is enabled. * * @return a <b>bool</b> of true if tracing is enabled and * active, or if tracing is disabled. */ bool isTraceable() { return isTracing() || (m_printMask & stk::LOG_TRACE) != 0; // Currently in a trace or tracing bit set }
void Tableau::addConstraint(size_t xIndex, SimplexRelation relation, const Real &rightSide) { if(xIndex < 1 || (int)xIndex >= getXCount()) { throwException(_T("addConstraint:Invalid xIndex=%s. Valid interval=[1..%s]"), FSZ(xIndex), FSZ(getXCount())); } Real currentValue = 0; int bvRow = -1; for(size_t i = 1; i < m_table.size(); i++) { if(m_table[i].m_basisVariable == (int)xIndex) { currentValue = getRightSide(i); bvRow = (int)i; break; } } String varName = getVariableName(xIndex); switch(relation) { case EQUALS : if(currentValue == rightSide) { trace(_T("addConstraint:No need to add constraint %s = %-16lg. %s already has the specified value."), varName.cstr(), getDouble(rightSide), varName.cstr()); return; } else if(currentValue < rightSide) { relation = GREATERTHAN; } else { relation = LESSTHAN; } break; case LESSTHAN : if(currentValue <= rightSide) { trace(_T("addConstraint:No need to add constraint %s <= %-16lg. %s=%-16lg."), varName.cstr(), getDouble(rightSide), varName.cstr(), getDouble(currentValue)); return; } break; case GREATERTHAN: if(currentValue >= rightSide) { trace(_T("addConstraint:No need to add constraint %s >= %-16lg. %s=%-16lg."), varName.cstr(), getDouble(rightSide), varName.cstr(), getDouble(currentValue)); return; } break; } if(isTracing(TRACE_ITERATIONS)) { trace(_T("Add constraint %s %s %lg"), varName.cstr(), getRelationString(relation), getDouble(rightSide)); } m_table.add(TableauRow(getMaxColumnCount())); const int newRowIndex = getConstraintCount(); addSlackColumn(); TableauRow &newRow = m_table[newRowIndex]; newRow.m_a[xIndex] = 1; slackVar(newRowIndex,m_slackCount) = getSlackFactor(relation); setRightSide(newRowIndex,rightSide); newRow.m_basisVariable = getSlackColumn(m_slackCount); objectFactor(newRow.m_basisVariable) = 1; // if(isTracing()) trace(_T("addConstraint before normalizing:\n %s"),toString().cstr()); if(bvRow >= 0) { addRowsToGetZero(newRowIndex,bvRow,xIndex); } if(getRightSide(newRowIndex) > 0) multiplyRow(newRowIndex,-1); // objectValue() += getRightSide(newRowIndex); }
// Parameter phase only for tracing SimplexResult Tableau::primalSimplex(int phase) { const int width = getWidth(); const int constraintCount = getConstraintCount(); for(int r = 1; r <= constraintCount; r++) { const TableauRow &row = m_table[r]; const int bv = row.m_basisVariable; const Real &a = row.m_a[bv]; if(a == 0) { continue; } Real factor = getObjectFactor(bv) / a; if(factor == 0) { trace(TRACE_WARNINGS,_T("Warning:Cost factor[%s] = 0."), getVariableName(bv).cstr()); continue; } for(int col = 0; col <= width; col++) { objectFactor(col) -= row.m_a[col] * factor; } objectFactor(bv) = 0; } bool looping = false; for(int iteration = 1;; iteration++) { if(isTracing(TRACE_ITERATIONS)) { trace(_T("Phase %d. Iteration %d"), phase, iteration); traceTableau(); // traceBasis(_T("Current basis:")); } int pivotColumn; Real minCost = 1; if(looping) { for(int col = 1; col <= width; col++) { // Apply Bland's anti-cycling rule step 1. const Real &cc = objectFactor(col); if(cc < -EPS) { minCost = cc; pivotColumn = col; break; } } } else { // else find pivot column the old way for(int col = 1; col <= width; col++) { const Real &cc = objectFactor(col); if(cc < minCost) { minCost = cc; pivotColumn = col; } } } if(minCost >= -EPS) { return SIMPLEX_SOLUTION_OK; // Optimal value found } int pivotRow = -1; Real minRatio = 0; if(looping) { // apply Bland's anti-cycling rule step 2. for(int r = 1; r <= constraintCount; r++) { const Real &ar = m_table[r].m_a[pivotColumn]; if(ar > 10*EPS) { const Real &br = getRightSide(r); const Real ratio = br / ar; if((pivotRow == -1) || (ratio < minRatio)) { minRatio = ratio; pivotRow = r; } } } if(pivotRow >= 0) { int minIndex = -1; for(int r = 1; r <= constraintCount; r++) { const Real &ar = m_table[r].m_a[pivotColumn]; if(ar > 10*EPS) { const Real &br = getRightSide(r); const Real ratio = br / ar; if(ratio == minRatio) { const int index = m_table[r].m_basisVariable; if(minIndex == -1 || index < minIndex) { minIndex = index; pivotRow = r; } } } } } } else { // else find pivot row the old way for(int r = 1; r <= constraintCount; r++) { const Real &ar = m_table[r].m_a[pivotColumn]; if(ar > EPS) { const Real &br = getRightSide(r); const Real ratio = br / ar; if(pivotRow == -1 || ratio < minRatio) { minRatio = ratio; pivotRow = r; } } } } if(pivotRow == -1) { return SIMPLEX_SOLUTION_UNLIMITED; } // Check for degeneracy traceDegeneracy(pivotRow, pivotColumn, minRatio); DictionaryKey dictKey(this); if(m_dictionarySet.contains(dictKey)) { looping = true; trace(TRACE_WARNINGS, _T("Looping. Applying Blands anti cycling rule.")); } else { m_dictionarySet.add(dictKey); } pivot(pivotRow,pivotColumn,true); } }
void Tableau::traceTableau() const { if(isTracing(TRACE_TABLEAU)) trace(_T("%s"),toString().cstr()); }
void Tableau::traceBasis(const TCHAR *label) const { if(isTracing(TRACE_SOLUTIONS)) trace(_T("%s\n%s"), label, getSolution().toString().cstr()); }