/** * Toggles whether debug information should be printed * @param printDebug whether to print debug logs or not */ public void toggleDebug(boolean printDebug){ this.printDebug = printDebug; DPrint.toggleCode(this.debugCode, this.printDebug); }
/** * A print line command for the given debug code. If that debug code is set to false, then the print will not occur. * @param c the debug code under which printing should be performed * @param s the string to print */ public static void cl(int c, String s){ c(c, s+"\n"); }
@Override public void agent_end(double v) { DPrint.cl(this.debugCode, "Got agent end message"); synchronized (nextStateReference) { this.lastReward = v; this.curStateIsTerminal = true; nextStateReference.val = curState; nextStateReference.notifyAll(); } }
DPrint.cl(this.debugCode, "Beginning trial " + (i+1) + "/" + this.nTrials); DPrint.toggleCode(w.getDebugId(), false); w.addWorldObserver(this.plotter); int id = 0;
/** * A universal print line whose behavior is determined by the <code>universalPrint</code> field * @param s the string to print */ public static void ul(String s){ u(s+"\n"); }
/** * Blocks the calling thread until a state is provided by the RLGlue server or the RLGlue experiment has ended. */ public void blockUntilStateReceived(){ synchronized(nextStateReference){ while(this.nextStateReference.val == null && !this.rlGlueExperimentFinished){ try{ DPrint.cl(debugCode, "Waiting for state from RLGlue Server..."); nextStateReference.wait(); } catch(InterruptedException ex){ ex.printStackTrace(); } } } }
@Override public void toggleDebugPrinting(boolean toggle){ DPrint.toggleCode(debugCode, toggle); }
/** * Sets the height and number of transition dynamics samples in a way that ensure epsilon optimality. * @param rmax the maximum reward value of the MDP * @param epsilon the epsilon optimality (amount that the estimated value function may diverge from the true optimal) * @param numActions the maximum number of actions that could be applied from a state */ public void setHAndCByMDPError(double rmax, double epsilon, int numActions){ double lambda = epsilon * (1. - this.gamma) * (1. - this.gamma) / 4.; double vmax = rmax / (1. - this.gamma); this.h = (int)logbase(this.gamma, lambda / vmax) + 1; this.c = (int)( (vmax*vmax / (lambda*lambda)) * (2 * this.h * Math.log(numActions*this.h * vmax * vmax / (lambda * lambda) + Math.log(rmax/lambda))) ); DPrint.cl(this.debugCode, "H = " + this.h); DPrint.cl(this.debugCode, "C = " + this.c); }
/** * Sets whether information during learning is printed to the terminal. Will automatically toggle the debug printing * for the underlying MLIRL that runs. * @param printDebug if true, information is printed to the terminal; if false then it is silent. */ public void toggleDebugPrinting(boolean printDebug){ DPrint.toggleCode(this.debugCode, printDebug); this.mlirlInstance.toggleDebugPrinting(printDebug); }
/** * Runs value iteration. Note that if the state samples have not been set, it will throw a runtime exception. */ public void runVI(){ for(int i = 0; i < this.maxIterations || this.maxIterations == -1; i++){ double change = this.runIteration(); DPrint.cl(this.debugCode, "Finished iteration " + i + "; max change: " + change); if(change < this.maxDelta){ break; } } }
/** * Loads this RLGlue {@link org.rlcommunity.rlglue.codec.AgentInterface} into RLGlue and runs its event loop in a * separate thread. */ public void loadAgent(){ DPrint.toggleCode(debugCode, this.printDebug); final AgentLoader loader = new AgentLoader(this); Thread eventThread = new Thread(new Runnable() { @Override public void run() { loader.run(); } }); eventThread.start(); }
/** * Plans from the input state and then returns a {@link burlap.behavior.policy.GreedyQPolicy} that greedily * selects the action with the highest Q-value and breaks ties uniformly randomly. * @param initialState the initial state of the planning problem * @return a {@link burlap.behavior.policy.GreedyQPolicy}. */ @Override public GreedyQPolicy planFromState(State initialState) { DPrint.cl(this.debugCode, "Beginning Planning."); int nr = 0; while(this.runRollout(initialState) > this.maxDiff && (nr < this.maxRollouts || this.maxRollouts == -1)){ nr++; } DPrint.cl(this.debugCode, "Finished planning with a total of " + this.numBellmanUpdates + " backups."); return new GreedyQPolicy(this); }
/** * Loads this RLGlue {@link org.rlcommunity.rlglue.codec.AgentInterface} into RLGlue using the specified host address and port * nd runs its event loop in a separate thread. * @param hostAddress the RLGlue host address. * @param portString the port on which to connect to RLGlue. */ public void loadAgent(String hostAddress, String portString){ DPrint.toggleCode(debugCode, this.printDebug); final AgentLoader loader = new AgentLoader(hostAddress, portString, this); Thread eventThread = new Thread(new Runnable() { @Override public void run() { loader.run(); } }); eventThread.start(); }
@Override public Action agent_start(Observation observation) { DPrint.cl(debugCode, "got agent start message, launching agent."); synchronized (nextStateReference) { this.curStateIsTerminal = false; this.lastReward = 0.; final State s = RLGlueDomain.stateFromObservation(observation); this.curState = s; this.nextStateReference.val = s; nextStateReference.notifyAll(); } Action toRet; synchronized (nextAction) { while(nextAction.val == null){ try{ DPrint.cl(debugCode, "Waiting for action..."); nextAction.wait(); } catch(InterruptedException ex){ ex.printStackTrace(); } } toRet = getRLGlueAction(nextAction.val); nextAction.val = null; } DPrint.cl(debugCode, "Returning first action."); return toRet; }
/** * Sets whether information during learning is printed to the terminal. Will automatically toggle the debug printing * for the underlying valueFunction as well. * @param printDebug if true, information is printed to the terminal; if false then it is silent. */ public void toggleDebugPrinting(boolean printDebug){ DPrint.toggleCode(this.debugCode, printDebug); this.request.getPlanner().toggleDebugPrinting(printDebug); }
DPrint.cl(this.debugCode, "Finished writing step csv file to: " + filePath);
DPrint.toggleCode(w.getDebugId(), false);