Ejemplo n.º 1
0
/*!
  \internal

  Does one iteration towards a better solution for the problem.
  See 'solveMaxHelper'.
*/
bool QSimplex::iterate()
{
    // Find Pivot column
    int pivotColumn = findPivotColumn();
    if (pivotColumn == -1)
        return false;

    // Find Pivot row for column
    int pivotRow = pivotRowForColumn(pivotColumn);
    if (pivotRow == -1) {
        qWarning() << "QSimplex: Unbounded problem!";
        return false;
    }

    // Normalize Pivot Row
    qreal pivot = valueAt(pivotRow, pivotColumn);
    if (pivot != 1.0)
        combineRows(pivotRow, pivotRow, (qreal(1.0) - pivot) / pivot);

    // Update other rows
    for (int row=0; row < rows; ++row) {
        if (row == pivotRow)
            continue;

        combineRows(row, pivotRow, -1 * valueAt(row, pivotColumn));
    }

    // Update first column
    setValueAt(pivotRow, 0, pivotColumn);

    //    dumpMatrix();
    //    qDebug("------------ end of iteration --------------\n");
    return true;
}
Ejemplo n.º 2
0
float HotPlate::valueAt(Point p, int offset_x, int offset_y) {
    Point np = p;
    np.x += offset_x;
    np.y += offset_y;
    // cover the edges.
    if(np.x<0 || np.y<0 || np.x >= width || np.y >= height) {
        if(p.x != np.x && p.y != np.y) {
            // If we are diagonal, let's try to get the point on the same
            // axis.
            if(np.y < 0) {
                return valueAt(p,offset_x,offset_y+1);
            } else if(np.y >= height) {
                return valueAt(p,offset_x,offset_y-1);
            } else if(np.x < 0) {
                return valueAt(p,offset_x+1,offset_y);
            } else if(np.x >= width) {
                return valueAt(p,offset_x-1,offset_y);
            }
        }
        // Arbitrary factor of 1.5 on edges
        if(swap) return temp2[p]/1.5;
        else return temp1[p]/1.5;
    }
    // cover the hot positions
    if(isLocked(np)) return 1;
    // Use the value listed in the screen pixel
    if(swap) return temp2[np];
    else return temp1[np];
}
status_t AudioPolicyMixCollection::getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix)
{
    if (strncmp(attr.tags, "addr=", strlen("addr=")) != 0) {
        return BAD_VALUE;
    }
    String8 address(attr.tags + strlen("addr="));

#ifdef LOG_NDEBUG
    ALOGV("getInputMixForAttr looking for address %s\n  mixes available:", address.string());
    for (size_t i = 0; i < size(); i++) {
            sp<AudioPolicyMix> policyMix = valueAt(i);
            AudioMix *mix = policyMix->getMix();
            ALOGV("\tmix %zu address=%s", i, mix->mDeviceAddress.string());
    }
#endif

    ssize_t index = indexOfKey(address);
    if (index < 0) {
        ALOGW("getInputMixForAttr() no policy for address %s", address.string());
        return BAD_VALUE;
    }
    sp<AudioPolicyMix> audioPolicyMix = valueAt(index);
    AudioMix *mix = audioPolicyMix->getMix();

    if (mix->mMixType != MIX_TYPE_PLAYERS) {
        ALOGW("getInputMixForAttr() bad policy mix type for address %s", address.string());
        return BAD_VALUE;
    }
    *policyMix = mix;
    return NO_ERROR;
}
Ejemplo n.º 4
0
bool HotPlate::stepHP() {
    float newValue;
    float n,s,e,w,here;
    bool changes = false;
    float epsilon = 1.0/512.0;
    for(int x = 0; x < width; x++) {
        for(int y = 0; y < height; y++) {
            Point p(x,y);

            here = valueAt(p,0,0);
            n = valueAt(p, 0,-1);
            s = valueAt(p, 0, 1);
            e = valueAt(p,-1, 0);
            w = valueAt(p, 1, 0);
            newValue = (here+n+s+e+w)/5;

            if(isLocked(p)) newValue = here;
            if(fabs(newValue - here) > epsilon) changes = true;

            if(swap) temp2[p] = newValue;
            else temp1[p] = newValue;
        }
    }
    swap = !swap;
    return changes;
}
Ejemplo n.º 5
0
void AutomationPattern::processMidiTime( const MidiTime & time )
{
	if( ! isRecording() )
	{
		if( time >= 0 && hasAutomation() )
		{
			const float val = valueAt( time );
			for( objectVector::iterator it = m_objects.begin();
							it != m_objects.end(); ++it )
			{
				if( *it )
				{
					( *it )->setAutomatedValue( val );
				}

			}	
		}
	}
	else
	{
		if( time >= 0 && ! m_objects.isEmpty() )
		{
			const float value = static_cast<float>( firstObject()->value<float>() );
			if( value != m_lastRecordedValue ) 
			{
				putValue( time, value, true );
				m_lastRecordedValue = value;
			}
			else if( valueAt( time ) != value )
			{
				removeValue( time, false );
			}
		}
	}
}
Ejemplo n.º 6
0
void AutomationPattern::flipY( int min, int max )
{
	timeMap tempMap = m_timeMap;
	timeMap::ConstIterator iterate = m_timeMap.lowerBound(0);
	float tempValue = 0;

	int numPoints = 0;

	for( int i = 0; ( iterate + i + 1 ) != m_timeMap.end() && ( iterate + i ) != m_timeMap.end() ; i++)
	{
		numPoints++;
	}

	for( int i = 0; i <= numPoints; i++ )
	{

		if ( min < 0 )
		{
			tempValue = valueAt( ( iterate + i ).key() ) * -1;
			putValue( MidiTime( (iterate + i).key() ) , tempValue, false);
		}
		else
		{
			tempValue = max - valueAt( ( iterate + i ).key() );
			putValue( MidiTime( (iterate + i).key() ) , tempValue, false);
		}
	}

	generateTangents();
	emit dataChanged();
}
Ejemplo n.º 7
0
/*!
  \internal
*/
void QSimplex::reducedRowEchelon()
{
    for (int i = 1; i < rows; ++i) {
        int factorInObjectiveRow = valueAt(i, 0);
        combineRows(0, i, -1 * valueAt(0, factorInObjectiveRow));
    }
}
Ejemplo n.º 8
0
int SymbolInfoJob::execute()
{
    int ret = 1;
    int idx = -1;
    if (end.isNull()) {
        auto symbol = project()->findSymbol(start, &idx);
        if (!symbol.isNull()) {
            write(symbol);
            ret = 0;
        }
    } else {
        assert(start.fileId() == end.fileId());
        auto symbols = project()->openSymbols(start.fileId());
        if (symbols && symbols->count()) {
            bool exact = false;
            uint32_t idx = symbols->lowerBound(start, &exact);
            if (exact) {
                write("(list");
                write(symbols->valueAt(idx++));
                ret = 0;
            } else {
                switch (idx) {
                case 0:
                    break;
                case std::numeric_limits<uint32_t>::max():
                    idx = symbols->count() - 1;
                    break;
                default:
                    --idx;
                    break;
                }
            }
            const uint32_t count = symbols->count();
            while (idx < count) {
                const Location loc = symbols->keyAt(idx);
                if (loc > end)
                    break;
                if (loc >= start) {
                    if (ret)
                        write("(list");
                    write(symbols->valueAt(idx));
                    ret = 0;
                }
                ++idx;
            }
            if (!ret)
                write(")");
        }
    }
    return ret;
}
Ejemplo n.º 9
0
/*!
  \internal
*/
int QSimplex::findPivotColumn()
{
    qreal min = 0;
    int minIndex = -1;

    for (int j = 0; j < columns-1; ++j) {
        if (valueAt(0, j) < min) {
            min = valueAt(0, j);
            minIndex = j;
        }
    }

    return minIndex;
}
Ejemplo n.º 10
0
void odeFunc( double time, double * u, double * du, void * udata )
{
	int i,j;
	TCpropensity(time, u, rates, udata);
	for (i=0; i < TCvars; ++i)
	{
		du[i] = 0;
		for (j=0; j < TCreactions; ++j)
		{
			if (valueAt(TCstoic,TCreactions,i,j) != 0)
			du[i] += rates[j]*valueAt(TCstoic,TCreactions,i,j);
		}
	}
}
double Mesh::valueAt(const Output* output, double xCoord, double yCoord) const
{
  if (!output)
    return -9999.0;

 // We want to find the value at the given coordinate
 // Loop through all the elements in the dataset and make a list of those

  std::vector<uint> candidateElementIds;
  for (int i = 0; i < mElems.count(); i++)
  {
    const BBox& bbox = projectedBBox(i);
    if (bbox.isPointInside(xCoord, yCoord))
      candidateElementIds.push_back(i);
  }

  if( candidateElementIds.size() == 0 )
      return -9999.0;

  double value;

  for (uint i=0; i < candidateElementIds.size(); i++)
  {
    uint elemIndex = candidateElementIds.at(i);
    if (!output->isActive(elemIndex))
      continue;

    if (valueAt(elemIndex, xCoord, yCoord, &value, output))
      // We successfully got a value, return it and leave
      return value;
  }

  return -9999.0;
}
Ejemplo n.º 12
0
float AutomationPattern::valueAt( const MidiTime & _time ) const
{
	if( m_timeMap.isEmpty() )
	{
		return 0;
	}

	if( m_timeMap.contains( _time ) )
	{
		return m_timeMap[_time];
	}

	// lowerBound returns next value with greater key, therefore we take
	// the previous element to get the current value
	timeMap::ConstIterator v = m_timeMap.lowerBound( _time );

	if( v == m_timeMap.begin() )
	{
		return 0;
	}
	if( v == m_timeMap.end() )
	{
		return (v-1).value();
	}

	return valueAt( v-1, _time - (v-1).key() );
}
audio_devices_t AudioPolicyMixCollection::getDeviceAndMixForInputSource(audio_source_t inputSource,
                                                                        audio_devices_t availDevices,
                                                                        AudioMix **policyMix)
{
    for (size_t i = 0; i < size(); i++) {
        AudioMix *mix = valueAt(i)->getMix();

        if (mix->mMixType != MIX_TYPE_RECORDERS) {
            continue;
        }
        for (size_t j = 0; j < mix->mCriteria.size(); j++) {
            if ((RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET == mix->mCriteria[j].mRule &&
                    mix->mCriteria[j].mValue.mSource == inputSource) ||
               (RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET == mix->mCriteria[j].mRule &&
                    mix->mCriteria[j].mValue.mSource != inputSource)) {
                if (availDevices & AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
                    if (policyMix != NULL) {
                        *policyMix = mix;
                    }
                    return AUDIO_DEVICE_IN_REMOTE_SUBMIX;
                }
                break;
            }
        }
    }
    return AUDIO_DEVICE_NONE;
}
Ejemplo n.º 14
0
const MemoryTablePrivate::value_type MemoryTablePrivate::valueAtIndex(size_t index, const TableMetadata *table)
{
    if (index >= table->count)
        return key_type();

    return valueAt(table->index[index].offset, table);
}
Ejemplo n.º 15
0
int add_stack(int depth) {
  int i, j;
  int old = swapSize;
  for(j = 0;j < MATRIX_SIZE;++j)
	  for(i = 0;i < MATRIX_SIZE;++i)
		  arr[i][j] = valueAt(i, j);
  swapSize = getSwapSize();
  assertTrue(swapSize >= old);
  if (depth > 1)
    if(add_stack(depth - 1) == -1)
		fail();
  for(j = 0;j < MATRIX_SIZE;++j)
	  for(i = 0;i < MATRIX_SIZE;++i)
		  if(!arr[i][j] == valueAt(i, j)) {
			  printf("incorrect value!\n");
			  fail();
		  }
}
void AudioPolicyMixCollection::closeOutput(sp<SwAudioOutputDescriptor> &desc)
{
    for (size_t i = 0; i < size(); i++) {
        sp<AudioPolicyMix> policyMix = valueAt(i);
        if (policyMix->getOutput() == desc) {
            policyMix->clearOutput();
        }
    }
}
Ejemplo n.º 17
0
const MemoryTablePrivate::value_type MemoryTablePrivate::value(const key_type &key, const TableMetadata *table)
{
    const IndexElement *tableEnd = end(table);
    const IndexElement *position = std::lower_bound(begin(table), tableEnd, key);
    if (position == tableEnd || position->key != key)
        return value_type();

    return valueAt(position->offset, table);
}
Ejemplo n.º 18
0
    string addBinary(string a, string b) {
        int m = a.size(), n = b.size();
        if (m == 0) { return b; }
        if (n == 0) { return a; }
        
        int carry = 0;
        string c = "";
        for (int i = 0; i < max(m, n); ++i) {
            int cur = valueAt(a, m-i-1) + valueAt(b, n-i-1) + carry;
            carry = cur / 2;
            if (cur % 2 == 0) { c.append("0"); }
            else { c.append("1"); }
        }

        if (carry) { c.append("1"); }

        return string(c.rbegin(), c.rend());
    }
Ejemplo n.º 19
0
/*!
  \internal

  Reads results from the simplified matrix and saves them in the
  "result" member of each QSimplexVariable.
*/
void QSimplex::collectResults()
{
    // All variables are zero unless overridden below.

    // ### Is this really needed? Is there any chance that an
    // important variable remains as non-basic at the end of simplex?
    for (int i = 0; i < variables.size(); ++i)
        variables[i]->result = 0;

    // Basic variables
    // Update the variable indicated in the first column with the value
    // in the last column.
    for (int i = 1; i < rows; ++i) {
        int index = valueAt(i, 0) - 1;
        if (index < variables.size())
            variables[index]->result = valueAt(i, columns - 1);
    }
}
Ejemplo n.º 20
0
audio_io_handle_t SwAudioOutputCollection::getA2dpOutput() const
{
    for (size_t i = 0; i < size(); i++) {
        sp<SwAudioOutputDescriptor> outputDesc = valueAt(i);
        if (!outputDesc->isDuplicated() && outputDesc->device() & AUDIO_DEVICE_OUT_ALL_A2DP) {
            return this->keyAt(i);
        }
    }
    return 0;
}
Ejemplo n.º 21
0
sp<SwAudioOutputDescriptor> SwAudioOutputCollection::getPrimaryOutput() const
{
    for (size_t i = 0; i < size(); i++) {
        const sp<SwAudioOutputDescriptor> outputDesc = valueAt(i);
        if (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) {
            return outputDesc;
        }
    }
    return NULL;
}
Ejemplo n.º 22
0
bool QueryJob::locationToString(Location location,
                                const std::function<void(LocationPiece, const String &)> &cb,
                                Flags<WriteFlag> writeFlags)
{
    if (location.isNull())
        return false;
    Flags<Location::ToStringFlag> kf = locationToStringFlags();
    kf &= ~Location::ShowContext;
    cb(Piece_Location, location.toString(kf, &mContextCache));
    if (!(writeFlags & NoContext) && !(queryFlags() & QueryMessage::NoContext))
        cb(Piece_Context, location.context(kf, &mContextCache));

    const bool containingFunction = queryFlags() & QueryMessage::ContainingFunction;
    const bool containingFunctionLocation = queryFlags() & QueryMessage::ContainingFunctionLocation;
    const bool cursorKind = queryFlags() & QueryMessage::CursorKind;
    const bool displayName = queryFlags() & QueryMessage::DisplayName;
    if (containingFunction || containingFunctionLocation || cursorKind || displayName || !mKindFilters.isEmpty()) {
        int idx;
        Symbol symbol = project()->findSymbol(location, &idx);
        if (symbol.isNull()) {
            error() << "Somehow can't find" << location << "in symbols";
        } else {
            if (!mKindFilters.filter(symbol))
                return false;
            if (displayName)
                cb(Piece_SymbolName, symbol.displayName());
            if (cursorKind)
                cb(Piece_Kind, symbol.kindSpelling());
            if (containingFunction || containingFunctionLocation) {
                const uint32_t fileId = location.fileId();
                const unsigned int line = location.line();
                const unsigned int column = location.column();
                auto fileMap = project()->openSymbols(location.fileId());
                if (fileMap) {
                    while (idx > 0) {
                        symbol = fileMap->valueAt(--idx);
                        if (symbol.location.fileId() != fileId)
                            break;
                        if (symbol.isDefinition()
                            && RTags::isContainer(symbol.kind)
                            && comparePosition(line, column, symbol.startLine, symbol.startColumn) >= 0
                            && comparePosition(line, column, symbol.endLine, symbol.endColumn) <= 0) {
                            if (containingFunction)
                                cb(Piece_ContainingFunctionName, symbol.symbolName);
                            if (containingFunctionLocation)
                                cb(Piece_ContainingFunctionLocation, symbol.location.toString(locationToStringFlags() & ~Location::ShowContext));
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Ejemplo n.º 23
0
sp<SwAudioOutputDescriptor> SwAudioOutputCollection::getOutputFromId(audio_port_handle_t id) const
{
    sp<SwAudioOutputDescriptor> outputDesc = NULL;
    for (size_t i = 0; i < size(); i++) {
        outputDesc = valueAt(i);
        if (outputDesc->getId() == id) {
            break;
        }
    }
    return outputDesc;
}
status_t AudioPolicyMixCollection::getAudioPolicyMix(const String8& address,
                                                     sp<AudioPolicyMix> &policyMix) const
{
    ssize_t index = indexOfKey(address);
    if (index < 0) {
        ALOGE("unregisterPolicyMixes(): mix for address %s not registered", address.string());
        return BAD_VALUE;
    }
    policyMix = valueAt(index);
    return NO_ERROR;
}
Ejemplo n.º 25
0
void AutomationPattern::recordValue(MidiTime time, float value)
{
	if( value != m_lastRecordedValue )
	{
		putValue( time, value, true );
		m_lastRecordedValue = value;
	}
	else if( valueAt( time ) != value )
	{
		removeValue( time );
	}
}
Ejemplo n.º 26
0
/*!
  \internal

  For a given pivot column, find the pivot row. That is, the row with the
  minimum associated "quotient" where:

  - quotient is the division of the value in the last column by the value
    in the pivot column.
  - rows with value less or equal to zero are ignored
  - if two rows have the same quotient, lines are chosen based on the
    highest variable index (value in the first column)

  The last condition avoids a bug where artificial variables would be
  left behind for the second-phase simplex, and with 'good'
  constraints would be removed before it, what would lead to incorrect
  results.
*/
int QSimplex::pivotRowForColumn(int column)
{
    qreal min = qreal(999999999999.0); // ###
    int minIndex = -1;

    for (int i = 1; i < rows; ++i) {
        qreal divisor = valueAt(i, column);
        if (divisor <= 0)
            continue;

        qreal quotient = valueAt(i, columns - 1) / divisor;
        if (quotient < min) {
            min = quotient;
            minIndex = i;
        } else if ((quotient == min) && (valueAt(i, 0) > valueAt(minIndex, 0))) {
            minIndex = i;
        }
    }

    return minIndex;
}
Ejemplo n.º 27
0
MemoryTablePrivate::Error MemoryTablePrivate::migrateTo(TableMetadata *other, const TableMetadata *table)
{
    // Copy all live elements to the other table
    const IndexElement *tableEnd(end(table));
    for (const IndexElement *it = begin(table); it != tableEnd; ++it) {
        MemoryTable::Error error = insert((*it).key, valueAt((*it).offset, table), other);
        if (error != MemoryTable::NoError)
            return error;
    }

    return MemoryTable::NoError;
}
Ejemplo n.º 28
0
    Real FdmHestonSolver::thetaAt(Real s, Real v) const {
        QL_REQUIRE(condition_->stoppingTimes().front() > 0.0,
                   "stopping time at zero-> can't calculate theta");

        calculate();
        Matrix thetaValues(resultValues_.rows(), resultValues_.columns());

        const Array& rhs = thetaCondition_->getValues();
        std::copy(rhs.begin(), rhs.end(), thetaValues.begin());

        return (BicubicSpline(x_.begin(), x_.end(), v_.begin(), v_.end(),
                              thetaValues)(std::log(s), v) - valueAt(s, v))
              / thetaCondition_->getTime();
    }
Ejemplo n.º 29
0
	void testInlineAutomation()
	{
		auto song = Engine::getSong();

		InstrumentTrack* instrumentTrack =
				dynamic_cast<InstrumentTrack*>(Track::create(Track::InstrumentTrack, song));

		Pattern* notePattern = dynamic_cast<Pattern*>(instrumentTrack->createTCO(0));
		notePattern->changeLength(MidiTime(4, 0));
		Note* note = notePattern->addNote(Note(MidiTime(4, 0)), false);
		note->createDetuning();

		DetuningHelper* dh = note->detuning();
		auto pattern = dh->automationPattern();
		pattern->setProgressionType( AutomationPattern::LinearProgression );
		pattern->putValue(MidiTime(0, 0), 0.0);
		pattern->putValue(MidiTime(4, 0), 1.0);

		QCOMPARE(pattern->valueAt(MidiTime(0, 0)), 0.0f);
		QCOMPARE(pattern->valueAt(MidiTime(1, 0)), 0.25f);
		QCOMPARE(pattern->valueAt(MidiTime(2, 0)), 0.5f);
		QCOMPARE(pattern->valueAt(MidiTime(4, 0)), 1.0f);
	}
Ejemplo n.º 30
0
Set<String> ListSymbolsJob::imenu(const std::shared_ptr<Project> &project)
{
    Set<String> out;
    const List<String> paths = pathFilters();
    if (paths.isEmpty()) {
        error() << "--imenu must take path filters";
        return out;
    }

    for (int i=0; i<paths.size(); ++i) {
        const Path file = paths.at(i);
        if (!file.isFile()) {
            error() << "Invalid path filter for --imenu" << file;
            continue;
        }
        const uint32_t fileId = Location::fileId(file);
        if (!fileId)
            continue;
        auto symbols = project->openSymbols(fileId);
        if (!symbols)
            continue;
        const int count = symbols->count();
        for (int j=0; j<count; ++j) {
            const Symbol &symbol = symbols->valueAt(j);
            if (RTags::isReference(symbol.kind))
                continue;
            switch (symbol.kind) {
            case CXCursor_VarDecl:
            case CXCursor_ParmDecl:
            case CXCursor_InclusionDirective:
            case CXCursor_EnumConstantDecl:
                break;
            case CXCursor_ClassDecl:
            case CXCursor_StructDecl:
            case CXCursor_ClassTemplate:
                if (!symbol.isDefinition())
                    break;
                // fall through
            default: {
                const String &symbolName = symbol.symbolName;
                if (!string.isEmpty() && !symbolName.contains(string))
                    continue;
                out.insert(symbolName);
                break; }
            }
        }
    }
    return out;
}