/* Returns infeasibility of the cut with respect to solution passed in i.e. is positive if cuts off that solution. solution is getNumCols() long.. */ double OsiColCut::violated(const double *solution) const { const CoinPackedVector &cutLbs = lbs(); const CoinPackedVector &cutUbs = ubs(); double sum = 0.0; int i; const int *column = cutLbs.getIndices(); int number = cutLbs.getNumElements(); const double *bound = cutLbs.getElements(); for (i = 0; i < number; i++) { int colIndx = column[i]; double newLb = bound[i]; if (newLb > solution[colIndx]) sum += newLb - solution[colIndx]; } column = cutUbs.getIndices(); number = cutUbs.getNumElements(); bound = cutUbs.getElements(); for (i = 0; i < number; i++) { int colIndx = column[i]; double newUb = bound[i]; if (newUb < solution[colIndx]) sum += solution[colIndx] - newUb; } return sum; }
/* Driver program to test above function */ int main() { int arr[] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}; int n = sizeof(arr)/sizeof(arr[0]); printf("Length of LBS is %d\n", lbs( arr, n ) ); return 0; }
static int yy_replace(u32 old_offset, u32 new_offset) { u32 x = 20; if (1.0*lbs(old_offset) < (bucket(old_offset, new_offset)+1)) { return 1; } return 0; }
void OsiColCut::print() const { const CoinPackedVector &cutLbs = lbs(); const CoinPackedVector &cutUbs = ubs(); int i; std::cout << "Column cut has " << cutLbs.getNumElements() << " lower bound cuts and " << cutUbs.getNumElements() << " upper bound cuts" << std::endl; for (i = 0; i < cutLbs.getNumElements(); i++) { int colIndx = cutLbs.getIndices()[i]; double newLb = cutLbs.getElements()[i]; std::cout << "[ x" << colIndx << " >= " << newLb << "] "; } for (i = 0; i < cutUbs.getNumElements(); i++) { int colIndx = cutUbs.getIndices()[i]; double newUb = cutUbs.getElements()[i]; std::cout << "[ x" << colIndx << " <= " << newUb << "] "; } std::cout << std::endl; }
bool core::queryBlocks(const std::list<crypto::hash>& knownBlockIds, uint64_t timestamp, uint64_t& resStartHeight, uint64_t& resCurrentHeight, uint64_t& resFullOffset, std::list<BlockFullInfo>& entries) { LockedBlockchainStorage lbs(m_blockchain_storage); uint64_t currentHeight = lbs->get_current_blockchain_height(); uint64_t startOffset = 0; if (!lbs->find_blockchain_supplement(knownBlockIds, startOffset)) { return false; } uint64_t startFullOffset = 0; if (!lbs->getLowerBound(timestamp, startOffset, startFullOffset)) startFullOffset = startOffset; resFullOffset = startFullOffset; if (startOffset != startFullOffset) { std::list<crypto::hash> blockIds; if (!lbs->getBlockIds(startOffset, std::min(uint64_t(BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT), startFullOffset - startOffset), blockIds)) { return false; } for (const auto& id : blockIds) { entries.push_back(BlockFullInfo()); entries.back().block_id = id; } } auto blocksLeft = std::min(BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT - entries.size(), size_t(BLOCKS_SYNCHRONIZING_DEFAULT_COUNT)); if (blocksLeft) { std::list<Block> blocks; lbs->get_blocks(startFullOffset, blocksLeft, blocks); for (auto& b : blocks) { BlockFullInfo item; item.block_id = get_block_hash(b); if (b.timestamp >= timestamp) { // query transactions std::list<Transaction> txs; std::list<crypto::hash> missedTxs; lbs->get_transactions(b.txHashes, txs, missedTxs); // fill data block_complete_entry& completeEntry = item; completeEntry.block = block_to_blob(b); for (auto& tx : txs) { completeEntry.txs.push_back(tx_to_blob(tx)); } } entries.push_back(std::move(item)); } } resCurrentHeight = currentHeight; resStartHeight = startOffset; return true; }