use of org.apache.commons.lang3.tuple.ImmutableTriple in project graal by graphik-team.
the class ChaseWithGRDAndUnfiers method next.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
Rule rule, unifiedRule;
Substitution unificator;
Queue<Triple<Rule, Substitution, InMemoryAtomSet>> newQueue = new LinkedList<Triple<Rule, Substitution, InMemoryAtomSet>>();
InMemoryAtomSet newAtomSet = new DefaultInMemoryGraphStore();
try {
while (!queue.isEmpty()) {
Triple<Rule, Substitution, InMemoryAtomSet> pair = queue.poll();
if (pair != null) {
unificator = pair.getMiddle();
InMemoryAtomSet part = pair.getRight();
rule = pair.getLeft();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("\nExecute rule: {} with unificator {}", rule, unificator);
}
unifiedRule = DefaultUnifierAlgorithm.getTargetVariablesSubstitution().createImageOf(rule);
unifiedRule = unificator.createImageOf(unifiedRule);
unifiedRule.getBody().removeAll(part);
unificator = targetToSource(unificator);
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(unifiedRule.getBody(), new LinkedList<Term>(unifiedRule.getFrontier()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Rule to execute: {}", unifiedRule.toString());
LOGGER.debug(" -- Query: {}", query.toString());
}
// Get projections
List<Substitution> projections = Iterators.toList(SmartHomomorphism.instance().execute(query, atomSet));
try {
for (Substitution proj : projections) {
InMemoryAtomSet newFacts = proj.createImageOf(unifiedRule.getHead());
ConjunctiveQuery q = new DefaultConjunctiveQuery(newFacts);
if (!SmartHomomorphism.instance().execute(q, newAtomSet).hasNext()) {
// Existential variables instantiation added to proj
CloseableIterator<Atom> it = hc.apply(unifiedRule, proj, atomSet);
if (it.hasNext()) {
LinkedListAtomSet foundPart = new LinkedListAtomSet();
foundPart.addAll(it);
newAtomSet.addAll(foundPart);
// Makes the projection compatible with triggered rules unifiers
Substitution compatibleProj = targetToSource(proj);
for (Pair<Rule, Substitution> p : this.grd.getTriggeredRulesWithUnifiers(rule)) {
Rule triggeredRule = p.getKey();
Substitution u = p.getValue();
if (u != null) {
Substitution comp = unificator.compose(u);
Substitution aggreg = compatibleProj.aggregate(comp);
aggreg = forgetSource(aggreg);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("-- -- Dependency: {}", triggeredRule);
LOGGER.debug("-- -- Substitution:{} ", compatibleProj);
LOGGER.debug("-- -- Unificator: {}", u);
LOGGER.debug("-- -- Aggregation: {}\n", aggreg);
}
if (aggreg != null) {
newQueue.add(new ImmutableTriple<Rule, Substitution, InMemoryAtomSet>(triggeredRule, aggreg, foundPart));
}
}
}
}
}
}
} catch (HomomorphismFactoryException e) {
throw new RuleApplicationException("Error during rule application", e);
} catch (HomomorphismException e) {
throw new RuleApplicationException("Error during rule application", e);
} catch (IteratorException e) {
throw new RuleApplicationException("Error during rule application", e);
}
}
}
queue = newQueue;
atomSet.addAll(newAtomSet);
} catch (Exception e) {
e.printStackTrace();
throw new ChaseException("An error occur pending saturation step.", e);
}
}
use of org.apache.commons.lang3.tuple.ImmutableTriple in project BWAPI4J by OpenBW.
the class MapTest method assertEquals_MiniTileAltitudes.
/**
* Tests that each MiniTile's Altitude for all WalkPositions match between
* the original BWAPI/BWEM in C++ and this Java port.
*/
private void assertEquals_MiniTileAltitudes(AdvancedData data, BWEM_DummyData dummyBwemData) {
final List<ImmutableTriple<WalkPosition, Integer, Integer>> wrongAltitudes = new ArrayList<>();
for (int y = 0; y < data.getMapData().getWalkSize().getY(); ++y) {
for (int x = 0; x < data.getMapData().getWalkSize().getX(); ++x) {
final WalkPosition w = new WalkPosition(x, y);
final int expected = dummyBwemData.getMiniTileAltitudes()[data.getMapData().getWalkSize().getX() * y + x];
final int actual = data.getMiniTile(w).getAltitude().intValue();
// Assert.assertEquals(w + ": mini tile altitude is wrong.", expected, actual);
if (expected != actual) {
wrongAltitudes.add(new ImmutableTriple<>(w, expected, actual));
}
}
}
for (final ImmutableTriple<WalkPosition, Integer, Integer> triple : wrongAltitudes) {
logger.warn("Wrong MiniTile altitude for WalkPosition: " + triple.getLeft().toString() + ", expected=" + triple.getMiddle() + ", actual=" + triple.getRight());
}
}
use of org.apache.commons.lang3.tuple.ImmutableTriple in project pravega by pravega.
the class EndToEndTransactionOrderTest method testOrder.
@Ignore
@Test(timeout = 100000)
public void testOrder() throws Exception {
final AtomicBoolean done = new AtomicBoolean(false);
CompletableFuture<Void> writer1 = startWriter("1", clientFactory, done);
CompletableFuture<Void> writer2 = startWriter("2", clientFactory, done);
CompletableFuture<Void> writer3 = startWriter("3", clientFactory, done);
CompletableFuture<Void> writer4 = startWriter("4", clientFactory, done);
// perform multiple scale stream operations so that rolling transactions may happen
Stream s = new StreamImpl("test", "test");
Map<Double, Double> map = new HashMap<>();
map.put(0.0, 1.0);
@Cleanup("shutdownNow") ScheduledExecutorService executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "order");
controller.scaleStream(s, Collections.singletonList(0L), map, executor).getFuture().get();
controller.scaleStream(s, Collections.singletonList(NameUtils.computeSegmentId(1, 1)), map, executor).getFuture().get();
controller.scaleStream(s, Collections.singletonList(NameUtils.computeSegmentId(2, 2)), map, executor).getFuture().get();
// stop writers
done.set(true);
CompletableFuture.allOf(writer1, writer2, writer3, writer4).join();
// wait for all transactions to commit
Futures.allOf(eventToTxnMap.entrySet().stream().map(x -> waitTillCommitted(controller, s, x.getValue(), uncommitted)).collect(Collectors.toList())).join();
assertTrue(uncommitted.isEmpty());
// read all events using a single reader and verify the order
List<Triple<Integer, UUID, String>> eventOrder = new LinkedList<>();
// create a reader
while (!eventToTxnMap.isEmpty()) {
EventRead<Integer> integerEventRead = reader.readNextEvent(SECONDS.toMillis(60));
if (integerEventRead.getEvent() != null) {
int event1 = integerEventRead.getEvent();
UUID txnId = eventToTxnMap.remove(event1);
String writerId = txnToWriter.get(txnId);
UUID first = writersList.get(writerId).remove(0);
eventOrder.add(new ImmutableTriple<>(event1, txnId, writerId));
assertEquals(first, txnId);
}
}
}
use of org.apache.commons.lang3.tuple.ImmutableTriple in project rskj by rsksmart.
the class RepositoryBlockStoreTest method test.
@Test
public void test() throws Exception {
// This Is how I produced RepositoryBlockStore_data.ser. I had a bitcoind in regtest with 613 blocks + genesis block
// NetworkParameters params = RegTestParams.get();
// Context context = new Context(params);
// Wallet wallet = new Wallet(context);
// BlockStore store = new SPVBlockStore(params, new File("spvBlockstore"));
// AbstractBlockChain chain = new BlockChain(context, wallet, store);
// PeerGroup peerGroup = new PeerGroup(context, chain);
// peerGroup.start();
// final DownloadProgressTracker listener = new DownloadProgressTracker();
// peerGroup.startBlockChainDownload(listener);
// listener.await();
// peerGroup.stop();
// StoredBlock storedBlock = chain.getChainHead();
// FileOutputStream fos = new FileOutputStream("RepositoryBlockStore_data.ser");
// ObjectOutputStream oos = new ObjectOutputStream(fos);
// for (int i = 0; i < 614; i++) {
// Triple<byte[], BigInteger , Integer> tripleStoredBlock = new ImmutableTriple<>(storedBlock.getHeader().bitcoinSerialize(), storedBlock.getChainWork(), storedBlock.getHeight());
// oos.writeObject(tripleStoredBlock);
// storedBlock = store.get(storedBlock.getHeader().getPrevBlockHash());
// }
// oos.close();
// Read original store
InputStream fileInputStream = ClassLoader.getSystemResourceAsStream("peg/RepositoryBlockStore_data.ser");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Repository repository = new RepositoryImplForTesting();
RskSystemProperties config = new RskSystemProperties();
RepositoryBlockStore store = new RepositoryBlockStore(config, repository, PrecompiledContracts.BRIDGE_ADDR);
for (int i = 0; i < 614; i++) {
Triple<byte[], BigInteger, Integer> tripleStoredBlock = (Triple<byte[], BigInteger, Integer>) objectInputStream.readObject();
BtcBlock header = RegTestParams.get().getDefaultSerializer().makeBlock(tripleStoredBlock.getLeft());
StoredBlock storedBlock = new StoredBlock(header, tripleStoredBlock.getMiddle(), tripleStoredBlock.getRight());
if (i == 0) {
store.setChainHead(storedBlock);
}
store.put(storedBlock);
}
// Create a new instance of the store
RepositoryBlockStore store2 = new RepositoryBlockStore(config, repository, PrecompiledContracts.BRIDGE_ADDR);
// Check a specific block that used to fail when we had a bug
assertEquals(store.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")), store2.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")));
// Check new instance content is identical to the original one
StoredBlock storedBlock = store.getChainHead();
StoredBlock storedBlock2 = store2.getChainHead();
int headHeight = storedBlock.getHeight();
for (int i = 0; i < headHeight; i++) {
assertNotNull(storedBlock);
assertEquals(storedBlock, storedBlock2);
Sha256Hash prevBlockHash = storedBlock.getHeader().getPrevBlockHash();
storedBlock = store.get(prevBlockHash);
storedBlock2 = store2.get(prevBlockHash);
}
}
use of org.apache.commons.lang3.tuple.ImmutableTriple in project gridss by PapenfussLab.
the class MisassemblyFixer method createContigTransitionOffsetLookup.
private static NavigableMap<Integer, ImmutableTriple<Integer, LongList, LongList>> createContigTransitionOffsetLookup(List<KmerPathSubnode> contig) {
NavigableMap<Integer, ImmutableTriple<Integer, LongList, LongList>> lookup = new TreeMap<Integer, ImmutableTriple<Integer, LongList, LongList>>();
int snoffset = 0;
for (int i = 0; i < contig.size() - 1; i++) {
KmerPathSubnode sn = contig.get(i);
LongArrayList snendkmers = new LongArrayList();
snendkmers.add(sn.lastKmer());
for (int j = 0; j < sn.node().collapsedKmerOffsets().size(); j++) {
int offset = sn.node().collapsedKmerOffsets().getInt(j);
if (offset == sn.length() - 1) {
snendkmers.add(sn.node().collapsedKmers().getLong(j));
}
}
KmerPathSubnode snext = contig.get(i + 1);
LongArrayList snextstartkmers = new LongArrayList();
snextstartkmers.add(snext.firstKmer());
for (int j = 0; j < snext.node().collapsedKmerOffsets().size(); j++) {
int offset = snext.node().collapsedKmerOffsets().getInt(j);
if (offset == 0) {
snextstartkmers.add(snext.node().collapsedKmers().getLong(j));
}
}
lookup.put(snoffset + sn.length() - 1, new ImmutableTriple<Integer, LongList, LongList>(i, snendkmers, snextstartkmers));
snoffset += sn.length();
}
return lookup;
}
Aggregations