public BackTestFileWriter(Strategy strategy) throws JArbitragerException { decimalFormat = NumberFormatterFactory.getNumberFormatter(5); dateFormat = new SimpleDateFormat("MMddyy,HHmmss"); dateFormat.setTimeZone(strategy.getTradingSchedule().getTimeZone()); File marketDataDir = new File(MARKET_DATA_DIR); if (!marketDataDir.exists()) { marketDataDir.mkdir(); } String fullFileName = MARKET_DATA_DIR + FILE_SEP + strategy.getName() + ".txt"; try { boolean fileExisted = new File(fullFileName).exists(); writer = new PrintWriter(new BufferedWriter(new FileWriter(fullFileName, true))); if (!fileExisted) { StringBuilder header = getHeader( strategy.getInstrument1().getContract().m_symbol, strategy.getInstrument2().getContract().m_symbol); writer.println(header); } } catch (IOException ioe) { throw new JArbitragerException("Could not write to file " + strategy.getName()); } }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy t_27, Strategy u_27) { ITermFactory termFactory = context.getFactory(); context.push("strategy_2_0"); Fail231: { IStrategoTerm k_141 = null; IStrategoTerm f_141 = null; IStrategoTerm g_141 = null; IStrategoTerm l_141 = null; if (term.getTermType() != IStrategoTerm.APPL || ext_out._consstrategy_2 != ((IStrategoAppl) term).getConstructor()) break Fail231; f_141 = term.getSubterm(0); g_141 = term.getSubterm(1); IStrategoList annos189 = term.getAnnotations(); k_141 = annos189; term = t_27.invoke(context, f_141); if (term == null) break Fail231; l_141 = term; term = u_27.invoke(context, g_141); if (term == null) break Fail231; term = termFactory.annotateTerm( termFactory.makeAppl(ext_out._consstrategy_2, new IStrategoTerm[] {l_141, term}), checkListAnnos(termFactory, k_141)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy p_17, Strategy q_17) { ITermFactory termFactory = context.getFactory(); context.push("SortListTl_2_0"); Fail121: { IStrategoTerm l_111 = null; IStrategoTerm j_111 = null; IStrategoTerm k_111 = null; IStrategoTerm m_111 = null; if (term.getTermType() != IStrategoTerm.APPL || out._consSortListTl_2 != ((IStrategoAppl) term).getConstructor()) break Fail121; j_111 = term.getSubterm(0); k_111 = term.getSubterm(1); IStrategoList annos109 = term.getAnnotations(); l_111 = annos109; term = p_17.invoke(context, j_111); if (term == null) break Fail121; m_111 = term; term = q_17.invoke(context, k_111); if (term == null) break Fail121; term = termFactory.annotateTerm( termFactory.makeAppl(out._consSortListTl_2, new IStrategoTerm[] {m_111, term}), checkListAnnos(termFactory, l_111)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy e_26, Strategy f_26) { ITermFactory termFactory = context.getFactory(); context.push("range_2_0"); Fail193: { IStrategoTerm q_134 = null; IStrategoTerm u_133 = null; IStrategoTerm x_133 = null; IStrategoTerm r_134 = null; if (term.getTermType() != IStrategoTerm.APPL || ext_out._consrange_2 != ((IStrategoAppl) term).getConstructor()) break Fail193; u_133 = term.getSubterm(0); x_133 = term.getSubterm(1); IStrategoList annos161 = term.getAnnotations(); q_134 = annos161; term = e_26.invoke(context, u_133); if (term == null) break Fail193; r_134 = term; term = f_26.invoke(context, x_133); if (term == null) break Fail193; term = termFactory.annotateTerm( termFactory.makeAppl(ext_out._consrange_2, new IStrategoTerm[] {r_134, term}), checkListAnnos(termFactory, q_134)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public void onStep(Controller controller, Snapshot snapshot) throws ConfusedException { // get our robot and the ball Robot ourRobot = snapshot.getBalle(); Ball ball = snapshot.getBall(); // if neither the ball nor the robot can be found then return if ((ourRobot.getPosition() == null) || (ball.getPosition() == null)) { return; } Strategy strategy = getStrategy(snapshot); LOG.debug("Selected strategy: " + strategy.getClass().getName()); // use strategy that was chosen setCurrentStrategy(strategy.getClass().getName()); try { strategy.step(controller, snapshot); } catch (ConfusedException e) { // If a strategy does not know what to do LOG.error("Wut Wut?", e); // Default to goToBallPFN Intercept.step(controller, snapshot); } }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy m_23, Strategy n_23) { ITermFactory termFactory = context.getFactory(); context.push("ExtOpDeclQ_2_0"); Fail142: { IStrategoTerm c_124 = null; IStrategoTerm z_123 = null; IStrategoTerm b_124 = null; IStrategoTerm d_124 = null; if (term.getTermType() != IStrategoTerm.APPL || ext_out._consExtOpDeclQ_2 != ((IStrategoAppl) term).getConstructor()) break Fail142; z_123 = term.getSubterm(0); b_124 = term.getSubterm(1); IStrategoList annos112 = term.getAnnotations(); c_124 = annos112; term = m_23.invoke(context, z_123); if (term == null) break Fail142; d_124 = term; term = n_23.invoke(context, b_124); if (term == null) break Fail142; term = termFactory.annotateTerm( termFactory.makeAppl(ext_out._consExtOpDeclQ_2, new IStrategoTerm[] {d_124, term}), checkListAnnos(termFactory, c_124)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy w_48, Strategy x_48) { ITermFactory termFactory = context.getFactory(); context.push("OpQ_2_0"); Fail375: { IStrategoTerm k_198 = null; IStrategoTerm i_198 = null; IStrategoTerm j_198 = null; IStrategoTerm l_198 = null; if (term.getTermType() != IStrategoTerm.APPL || out._consOpQ_2 != ((IStrategoAppl) term).getConstructor()) break Fail375; i_198 = term.getSubterm(0); j_198 = term.getSubterm(1); IStrategoList annos318 = term.getAnnotations(); k_198 = annos318; term = w_48.invoke(context, i_198); if (term == null) break Fail375; l_198 = term; term = x_48.invoke(context, j_198); if (term == null) break Fail375; term = termFactory.annotateTerm( termFactory.makeAppl(out._consOpQ_2, new IStrategoTerm[] {l_198, term}), checkListAnnos(termFactory, k_198)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke( Context context, IStrategoTerm term, Strategy p_29, Strategy q_29, Strategy r_29, Strategy s_29, Strategy t_29) { ITermFactory termFactory = context.getFactory(); context.push("ClassDecHead_5_0"); Fail73: { IStrategoTerm f_136 = null; IStrategoTerm r_135 = null; IStrategoTerm u_135 = null; IStrategoTerm y_135 = null; IStrategoTerm b_136 = null; IStrategoTerm d_136 = null; IStrategoTerm h_136 = null; IStrategoTerm j_136 = null; IStrategoTerm k_136 = null; IStrategoTerm l_136 = null; if (term.getTermType() != IStrategoTerm.APPL || out._consClassDecHead_5 != ((IStrategoAppl) term).getConstructor()) break Fail73; r_135 = term.getSubterm(0); u_135 = term.getSubterm(1); y_135 = term.getSubterm(2); b_136 = term.getSubterm(3); d_136 = term.getSubterm(4); IStrategoList annos49 = term.getAnnotations(); f_136 = annos49; term = p_29.invoke(context, r_135); if (term == null) break Fail73; h_136 = term; term = q_29.invoke(context, u_135); if (term == null) break Fail73; j_136 = term; term = r_29.invoke(context, y_135); if (term == null) break Fail73; k_136 = term; term = s_29.invoke(context, b_136); if (term == null) break Fail73; l_136 = term; term = t_29.invoke(context, d_136); if (term == null) break Fail73; term = termFactory.annotateTerm( termFactory.makeAppl( out._consClassDecHead_5, new IStrategoTerm[] {h_136, j_136, k_136, l_136, term}), checkListAnnos(termFactory, f_136)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public int loop() { for (Strategy currentStrategy : strategies) { if (currentStrategy.isValid()) { painter.setTotalMoneyMade(moneyHandler.getTotalMoneyMade()); currentStrategy.execute(); } } return Random.nextInt(300, 600); }
@SuppressWarnings("unchecked") public boolean containsKey(final Object k) { // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (K) (k)))) return true; pos = (pos + 1) & mask; } return false; }
@SuppressWarnings("unchecked") public char getChar(final Object k) { // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (K) (k)))) return value[pos]; pos = (pos + 1) & mask; } return defRetValue; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy m_18) { ITermFactory termFactory = context.getFactory(); context.push("BuildDefaultPT_1_0"); Fail139: { IStrategoTerm a_114 = null; IStrategoTerm z_113 = null; if (term.getTermType() != IStrategoTerm.APPL || out._consBuildDefaultPT_1 != ((IStrategoAppl) term).getConstructor()) break Fail139; z_113 = term.getSubterm(0); IStrategoList annos126 = term.getAnnotations(); a_114 = annos126; term = m_18.invoke(context, z_113); if (term == null) break Fail139; term = termFactory.annotateTerm( termFactory.makeAppl(out._consBuildDefaultPT_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, a_114)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy q_23) { ITermFactory termFactory = context.getFactory(); context.push("OpDeclInj_1_0"); Fail144: { IStrategoTerm s_124 = null; IStrategoTerm q_124 = null; if (term.getTermType() != IStrategoTerm.APPL || ext_out._consOpDeclInj_1 != ((IStrategoAppl) term).getConstructor()) break Fail144; q_124 = term.getSubterm(0); IStrategoList annos114 = term.getAnnotations(); s_124 = annos114; term = q_23.invoke(context, q_124); if (term == null) break Fail144; term = termFactory.annotateTerm( termFactory.makeAppl(ext_out._consOpDeclInj_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, s_124)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy a_15) { ITermFactory termFactory = context.getFactory(); context.push("ElemValArrayInit_1_0"); Fail20: { IStrategoTerm j_100 = null; IStrategoTerm i_100 = null; if (term.getTermType() != IStrategoTerm.APPL || renaming._consElemValArrayInit_1 != ((IStrategoAppl) term).getConstructor()) break Fail20; i_100 = term.getSubterm(0); IStrategoList annos6 = term.getAnnotations(); j_100 = annos6; term = a_15.invoke(context, i_100); if (term == null) break Fail20; term = termFactory.annotateTerm( termFactory.makeAppl(renaming._consElemValArrayInit_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, j_100)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy p_18) { ITermFactory termFactory = context.getFactory(); context.push("Signature_1_0"); Fail58: { IStrategoTerm a_110 = null; IStrategoTerm z_109 = null; if (term.getTermType() != IStrategoTerm.APPL || extraction._consSignature_1 != ((IStrategoAppl) term).getConstructor()) break Fail58; z_109 = term.getSubterm(0); IStrategoList annos34 = term.getAnnotations(); a_110 = annos34; term = p_18.invoke(context, z_109); if (term == null) break Fail58; term = termFactory.annotateTerm( termFactory.makeAppl(extraction._consSignature_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, a_110)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy c_21) { ITermFactory termFactory = context.getFactory(); context.push("LRule_1_0"); Fail88: { IStrategoTerm v_116 = null; IStrategoTerm u_116 = null; if (term.getTermType() != IStrategoTerm.APPL || extraction._consLRule_1 != ((IStrategoAppl) term).getConstructor()) break Fail88; u_116 = term.getSubterm(0); IStrategoList annos64 = term.getAnnotations(); v_116 = annos64; term = c_21.invoke(context, u_116); if (term == null) break Fail88; term = termFactory.annotateTerm( termFactory.makeAppl(extraction._consLRule_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, v_116)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy d_28) { ITermFactory termFactory = context.getFactory(); context.push("iter_1_0"); Fail225: { IStrategoTerm z_142 = null; IStrategoTerm y_142 = null; if (term.getTermType() != IStrategoTerm.APPL || extraction._consiter_1 != ((IStrategoAppl) term).getConstructor()) break Fail225; y_142 = term.getSubterm(0); IStrategoList annos186 = term.getAnnotations(); z_142 = annos186; term = d_28.invoke(context, y_142); if (term == null) break Fail225; term = termFactory.annotateTerm( termFactory.makeAppl(extraction._consiter_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, z_142)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy s_19) { ITermFactory termFactory = context.getFactory(); context.push("Block_1_0"); Fail72: { IStrategoTerm q_112 = null; IStrategoTerm p_112 = null; if (term.getTermType() != IStrategoTerm.APPL || renaming._consBlock_1 != ((IStrategoAppl) term).getConstructor()) break Fail72; p_112 = term.getSubterm(0); IStrategoList annos56 = term.getAnnotations(); q_112 = annos56; term = s_19.invoke(context, p_112); if (term == null) break Fail72; term = termFactory.annotateTerm( termFactory.makeAppl(renaming._consBlock_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, q_112)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy x_29) { ITermFactory termFactory = context.getFactory(); context.push("ExtendsInterfaces_1_0"); Fail76: { IStrategoTerm x_136 = null; IStrategoTerm w_136 = null; if (term.getTermType() != IStrategoTerm.APPL || out._consExtendsInterfaces_1 != ((IStrategoAppl) term).getConstructor()) break Fail76; w_136 = term.getSubterm(0); IStrategoList annos52 = term.getAnnotations(); x_136 = annos52; term = x_29.invoke(context, w_136); if (term == null) break Fail76; term = termFactory.annotateTerm( termFactory.makeAppl(out._consExtendsInterfaces_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, x_136)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
/** * Resizes the map. * * <p>This method implements the basic rehashing strategy, and may be overriden by subclasses * implementing different rehashing strategies (e.g., disk-based rehashing). However, you should * not override this method unless you understand the internal workings of this class. * * @param newN the new size */ @SuppressWarnings("unchecked") protected void rehash(final int newN) { int i = 0, pos; final boolean used[] = this.used; K k; final K key[] = this.key; final char value[] = this.value; final int newMask = newN - 1; final K newKey[] = (K[]) new Object[newN]; final char newValue[] = new char[newN]; final boolean newUsed[] = new boolean[newN]; for (int j = size; j-- != 0; ) { while (!used[i]) i++; k = key[i]; pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & newMask; while (newUsed[pos]) pos = (pos + 1) & newMask; newUsed[pos] = true; newKey[pos] = k; newValue[pos] = value[i]; i++; } n = newN; mask = newMask; maxFill = maxFill(n, f); this.key = newKey; this.value = newValue; this.used = newUsed; }
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy n_18) { ITermFactory termFactory = context.getFactory(); context.push("Overlays_1_0"); Fail56: { IStrategoTerm u_109 = null; IStrategoTerm t_109 = null; if (term.getTermType() != IStrategoTerm.APPL || extraction._consOverlays_1 != ((IStrategoAppl) term).getConstructor()) break Fail56; t_109 = term.getSubterm(0); IStrategoList annos32 = term.getAnnotations(); u_109 = annos32; term = n_18.invoke(context, t_109); if (term == null) break Fail56; term = termFactory.annotateTerm( termFactory.makeAppl(extraction._consOverlays_1, new IStrategoTerm[] {term}), checkListAnnos(termFactory, u_109)); context.popOnSuccess(); if (true) return term; } context.popOnFailure(); return null; }
@SuppressWarnings("unchecked") public Character remove(final Object ok) { final K k = (K) (ok); // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (K) (k)))) { size--; final char v = value[pos]; shiftKeys(pos); return (Character.valueOf(v)); } pos = (pos + 1) & mask; } return (null); }
private void testStrategy(Strategy distanceStrategy) throws UDFArgumentException, HiveException { Distance distance = new Distance(); Object result = distance.evaluate(distanceStrategy.getName(), "hello", "hello"); Assert.assertNotNull(result); Float dist = (Float) result; Assert.assertEquals(1.0, dist, 0f); }
/* (non-Javadoc) * @see org.apache.commons.lang3.time.DateParser#parse(java.lang.String, java.text.ParsePosition) */ @Override public Date parse(final String source, final ParsePosition pos) { final int offset = pos.getIndex(); final Matcher matcher = parsePattern.matcher(source.substring(offset)); if (!matcher.lookingAt()) { return null; } // timing tests indicate getting new instance is 19% faster than cloning final Calendar cal = Calendar.getInstance(timeZone, locale); cal.clear(); for (int i = 0; i < strategies.length; ) { final Strategy strategy = strategies[i++]; strategy.setCalendar(this, cal, matcher.group(i)); } pos.setIndex(offset + matcher.end()); return cal.getTime(); }
public void modelChanged(Event event, Object value) { switch (event) { case StrategyUpdate: MarketDepth marketDepth = strategy.getMarketBook().getMarketDepth(); cumBidAskSizesLabel.setText(marketDepth.getSizes()); bidAskLabel.setText(marketDepth.getTop()); break; } }
public GameResponse turn(GameRequest gameRequest) { logger.info("Turn {} of {}", gameRequest.getCurrentTurn(), gameRequest.getMaximumTurns()); turnRequests.add(gameRequest); gameState.updateState(gameRequest.getStates()); strategy.move(); return gameState.getMoves(); }
public SoldierRobot(RobotController rc) throws GameActionException { super(rc); NavSystem.init(this); if (Clock.getRoundNum() < 10) { soldierState = soldierState.SCOUTING; } else { ChannelType channel = EncampmentJobSystem.findJob(); if (channel != null) { unassigned = false; EncampmentJobSystem.updateJobTaken(); } // TODO: this will f**k up if we ever build artillery for non-nuke bots // LEARN THE STRATEGY Message message = BroadcastSystem.read(ChannelType.STRATEGY); if (message.isValid && message.body < Strategy.values().length && message.body >= 0) { strategy = Strategy.values()[message.body]; } else { // we couldn't read the strategy channel MapLocation[] alliedEncampmentSquares = rc.senseAlliedEncampmentSquares(); if (alliedEncampmentSquares.length == 0) { strategy = Strategy.ECON; } else { Robot robot = (Robot) rc.senseObjectAtLocation(alliedEncampmentSquares[0]); RobotInfo robotInfo = rc.senseRobotInfo(robot); if (robotInfo.type == RobotType.ARTILLERY) { strategy = Strategy.NUKE; } else { strategy = Strategy.ECON; } } } // rc.setIndicatorString(2, strategy.toString()); rallyPoint = findRallyPoint(); rSquared = DataCache.rushDistSquared / 4; initializeMining(); } }
/* * The following methods implements some basic building blocks used by * all accessors. They are (and should be maintained) identical to those used in OpenHashSet.drv. */ public char put(final K k, final char v) { // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (K) (k)))) { final char oldValue = value[pos]; value[pos] = v; return oldValue; } pos = (pos + 1) & mask; } used[pos] = true; key[pos] = k; value[pos] = v; if (++size >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable(); return defRetValue; }
/** * Returns a hash code for this map. * * <p>This method overrides the generic method provided by the superclass. Since <code>equals() * </code> is not overriden, it is important that the value returned by this method is the same * value as the one returned by the overriden method. * * @return a hash code for this map. */ public int hashCode() { int h = 0; for (int j = size, i = 0, t = 0; j-- != 0; ) { while (!used[i]) i++; if (this != key[i]) t = (strategy.hashCode((K) (key[i]))); t ^= (value[i]); h += t; i++; } return h; }
public Character put(final K ok, final Character ov) { final char v = ((ov).charValue()); final K k = (ok); // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode((K) (k)))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (K) (k)))) { final Character oldValue = (Character.valueOf(value[pos])); value[pos] = v; return oldValue; } pos = (pos + 1) & mask; } used[pos] = true; key[pos] = k; value[pos] = v; if (++size >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable(); return (null); }