本文整理汇总了Java中sim.engine.SimState类的典型用法代码示例。如果您正苦于以下问题:Java SimState类的具体用法?Java SimState怎么用?Java SimState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimState类属于sim.engine包,在下文中一共展示了SimState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(SimState simState) {
daysWaiting++;
if(daysWaiting >= speedInDays)
{
Pair<Integer,Integer> waypoint = waypoints.get(currentWaypoint);
positionX+= Math.signum(waypoint.getFirst()-positionX);
positionY+= Math.signum(waypoint.getSecond()-positionY);
daysWaiting = 0;
updateWaypoint();
}
}
示例2: start
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void start(FishState model) {
Preconditions.checkArgument(receipt == null, "already started, love");
//start all tiles
for(Object element : rasterBackingGrid.elements())
{
SeaTile tile = (SeaTile) element; //cast
tile.start(model);
}
Preconditions.checkArgument(receipt==null);
//reset fished map count
receipt =
model.scheduleEveryDay(new Steppable() {
@Override
public void step(SimState simState) {
dailyTrawlsMap.setTo(0);
}
},StepOrder.DAWN);
}
示例3: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(SimState simState)
{
stepsLeft--;
stepsLeft = FishStateUtilities.round(stepsLeft);
//notice the dithering when steps don't match really well
if(stepsLeft<=0 || (stepsLeft < 1 && random.nextBoolean(1-stepsLeft)))
{
Log.trace("OSMOSE step!");
osmoseSimulation.oneStep();
stepsLeft=stepRatio; //reset
toReset.forEach(LocalOsmoseWithoutRecruitmentBiology::osmoseStep);
}
assert stepsLeft > 0;
}
示例4: step
import sim.engine.SimState; //导入依赖的package包/类
/**
* next element of the time series is sent to actuator
*/
@Override
public void step(SimState simState)
{
//starting or finished the list? start again!
if(iterator == null)
iterator= timeSeries.iterator();
if(!iterator.hasNext()) {
if (startOver)
iterator = timeSeries.iterator();
else
return;
}
Double nextGasPrice = iterator.next();
actuator.accept(nextGasPrice);
}
示例5: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(SimState simState) {
FishState model = (FishState) simState;
if(model.getYear()>=startYear) {
IntGrid2D trawls = model.getMap().getDailyTrawlsMap();
//remember to flip it
for (int x = 0; x < model.getMap().getWidth(); x++)
for (int y = 0; y < model.getMap().getHeight(); y++)
{
if(model.getMap().getSeaTile(x,y).getAltitude()>0)
towHeatmap[x][model.getMap().getHeight() - y - 1] = Double.NaN;
else
towHeatmap[x][model.getMap().getHeight() - y - 1] += trawls.get(x, y);
}
}
}
示例6: scheduleOnceAtTheBeginningOfYear
import sim.engine.SimState; //导入依赖的package包/类
/**
* will step this object only once when the specific year starts. If that year is in the past, it won't step.
* Implementation wise unfortunately I just check every year to see whether to step this or not. It's quite silly.
* @param steppable
* @param order
* @param year
*/
public Stoppable scheduleOnceAtTheBeginningOfYear(Steppable steppable,StepOrder order, int year)
{
final Steppable container = new Steppable() {
@Override
public void step(SimState simState) {
//the plus one is because when this is stepped it's the 365th day
if(((FishState) simState).getYear()+1 == year) {
steppable.step(simState);
}
}
};
return scheduleEveryYear(container,order);
}
示例7: apply
import sim.engine.SimState; //导入依赖的package包/类
/**
* Applies this function to the given argument.
*
* @param fishState the function argument
* @return the function result
*/
@Override
public ExternalOpenCloseSeason apply(FishState fishState) {
return locker.presentKey
(fishState,
new Supplier<ExternalOpenCloseSeason>() {
@Override
public ExternalOpenCloseSeason get() {
ExternalOpenCloseSeason toReturn = new ExternalOpenCloseSeason();
fishState.scheduleEveryXDay(new Steppable() {
@Override
public void step(SimState simState) {
toReturn.setOpen(fishState.getRandom().nextBoolean());
}
}, StepOrder.POLICY_UPDATE,30);
return toReturn;
}
});
}
示例8: step
import sim.engine.SimState; //导入依赖的package包/类
/**
* open or close the world
* @param simState
*/
@Override
public void step(SimState simState)
{
//ask the policy what should be done
ShodanStateOil state = ShodanStateOil.fromState((FishState) simState);
Action action = policy.action(state);
StringBuilder qvalues = new StringBuilder();
for(QValue qValue : qfunction.qValues(state))
qvalues.append(qValue.a.actionName()).append(" -> ").append(qValue.q).append(" | ");
System.out.println("shodan says: " +action + " , " + qvalues.toString());
//actuate to the fishstate
if(action.actionName().equals(ShodanEnvironment.ACTION_OPEN))
regulation.setOpen(true);
else
{
assert action.actionName().equals(ShodanEnvironment.ACTION_CLOSE);
regulation.setOpen(false);
}
}
示例9: start
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void start(FishState model, Fisher fisher) {
//shedule yourself to check for profits every year
if(stoppable != null)
throw new RuntimeException("Already started!");
Steppable steppable = new Steppable() {
@Override
public void step(SimState simState) {
checkIfQuit(fisher);
}
};
this.stoppable = model.scheduleEveryYear(steppable, StepOrder.DAWN);
decorated.start(model,fisher);
}
示例10: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(SimState simState)
{
LinkedList<SeaTile> toRemove = new LinkedList<>();
if(memories.size() > minimumNumberOfMemoriesBeforeForgetting)
{
for (Map.Entry<SeaTile, LocationMemory<T>> memory : memories.entrySet()) {
int age = memory.getValue().age();
if (age >= minimumMemoryAgeInDaysBeforeForgetting &&
((FishState) simState).getRandom().nextBoolean(dailyForgettingProbability))
toRemove.add(memory.getKey());
}
toRemove.forEach(memories::remove);
}
}
示例11: start
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void start() {
super.start();
initSeries();
scheduleRepeatingImmediatelyAfter(new Steppable() {
private static final long serialVersionUID = 1L;
private int lastCycleIndex = 0;
@Override
public void step(final SimState state) {
final AbstractModel model = (AbstractModel) state;
final int currentCycleIndex = (int) Simulation.getFloorTime();
if (model.schedule.getTime() != Schedule.AFTER_SIMULATION
&& currentCycleIndex != lastCycleIndex) {
scheduleSeries(model);
lastCycleIndex = currentCycleIndex;
}
}
});
}
示例12: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(final SimState state) {
if ( activityChanceDistribution.nextDouble() < activityChanceThreshold ) {
final double amount = determineRandomAmountToDepositOrWithdraw();
if ( amount < 0 ) {
try {
credit( - amount );
} catch (final InsufficientFundsException e) {
// If there's not enough money, spend all of it
cashLedger.pull(this.getDepositValue());
}
} else {
debit( amount );
}
}
}
示例13: step
import sim.engine.SimState; //导入依赖的package包/类
@Override
public void step(final SimState state) {
// setting up random deposits
if ( depositFrequencyDistribution.nextDouble() < depositChanceThreshold ) {
final double amount = depositSizeDistribution.nextDouble() * randomDepositMultiplier + randomDepositOffset;
if ( amount < 0 ) {
try {
credit( - amount );
} catch (final InsufficientFundsException e) {
// If there's not enough money, spend all of it
cashLedger.pull(this.getDepositValue());
}
} else {
debit( amount );
}
}
// setting up random loan requests
if ( loanFrequencyDistribution.nextDouble() > loanChanceThreshold ) {
this.considerCommercialLoanMarkets();
}
}
示例14: RecordingTestModel
import sim.engine.SimState; //导入依赖的package包/类
public RecordingTestModel(long seed) {
super(seed);
for (int i = 0; i < agentNum; i++) {
RecordingTestAgent recordingTestAgent = new RecordingTestAgent(i);
agentList.add(recordingTestAgent);
anonymList.add(recordingTestAgent);
}
schedule.scheduleRepeating(
new Steppable() {
private static final long
serialVersionUID = 1023983258758828337L;
@Override
public void step(SimState state) {
someDouble = state.schedule.getTime();
intList.add((int) Math.round(someDouble));
}
},
1);
}
示例15: recording
import sim.engine.SimState; //导入依赖的package包/类
@Test(enabled = false)
public void recording() throws URISyntaxException, IOException {
SimState model;
model = new RecordingTestModel(0);
model.start();
for (int step = 0; step < 23; ++step)
model.schedule.step(model);
model.finish();
File resultFile = new File("testrecorder.csv");
File goodResultFile = new File(
RecordingTest.class.getResource(
"testrecorder.csv").toURI());
Assert.assertTrue(resultFile.exists());
Assert.assertTrue(areSameFiles(resultFile, goodResultFile),
"results file does not match the predefined results file");
}