本文整理汇总了C++中SIMULATOR类的典型用法代码示例。如果您正苦于以下问题:C++ SIMULATOR类的具体用法?C++ SIMULATOR怎么用?C++ SIMULATOR使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SIMULATOR类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Free
void BELIEF_PROBA_STATE::Free(const SIMULATOR& simulator) {
if( MH )
delete[] MH;
MH = 0;
if( _uniqueState )
simulator.FreeState(_uniqueState);
_uniqueState = 0;
}
示例2: Copy
void BELIEF_STATE::Copy(const BELIEF_STATE* beliefs, const SIMULATOR& simulator)
{
for (std::vector<STATE*>::const_iterator i_state = beliefs->Samples.begin();
i_state != beliefs->Samples.end(); ++i_state)
{
AddSample(simulator.Copy(**i_state));
}
}
示例3: Free
void BELIEF_STATE::Free(const SIMULATOR& simulator)
{
for (std::vector<STATE*>::iterator i_state = Samples.begin();
i_state != Samples.end(); ++i_state)
{
simulator.FreeState(*i_state);
}
Samples.clear();
}
示例4: Real
EXPERIMENT::EXPERIMENT(const SIMULATOR& real,
const SIMULATOR& simulator, const string& outputFile,
EXPERIMENT::PARAMS& expParams, MCTS::PARAMS& searchParams)
: Real(real),
Simulator(simulator),
OutputFile(outputFile.c_str()),
ExpParams(expParams),
SearchParams(searchParams)
{
if (ExpParams.AutoExploration)
{
if (SearchParams.UseRave)
SearchParams.ExplorationConstant = 0;
else
SearchParams.ExplorationConstant = simulator.GetRewardRange();
}
MCTS::InitFastUCB(SearchParams.ExplorationConstant);
}
示例5: handle
virtual void handle() {
HOST* h = new HOST;
h->t = t + ran_exp(HOST_LIFE_MEAN);
hosts.insert(h);
sim.insert(h);
t += ran_exp(86400./HOSTS_PER_DAY);
sim.insert(this);
}
示例6: main
int main() {
HOST_ARRIVAL *h = new HOST_ARRIVAL;
h->t = 0;
sim.insert(h);
REPORT_STATS* r = new REPORT_STATS;
r->t = 0;
sim.insert(r);
sim.simulate(200*86400);
}
示例7: main
int main(int argc, char** argv) {
POLICY policy;
// default policy
//
policy.replication = 2;
policy.coding_levels = 2;
policy.codings[0].n = 10;
policy.codings[0].k = 6;
policy.codings[0].m = 16;
policy.codings[0].n_upload = 12;
policy.codings[1].n = 10;
policy.codings[1].k = 6;
policy.codings[1].m = 16;
policy.codings[1].n_upload = 12;
for (int i=1; i<argc; i++) {
if (!strcmp(argv[i], "--policy")) {
int retval = policy.parse(argv[++i]);
if (retval) exit(1);
} else if (!strcmp(argv[i], "--host_life_mean")) {
params.host_life_mean = atof(argv[++i]);
} else if (!strcmp(argv[i], "--connect_interval")) {
params.connect_interval = atof(argv[++i]);
} else if (!strcmp(argv[i], "--mean_xfer_rate")) {
params.mean_xfer_rate = atof(argv[++i]);
} else if (!strcmp(argv[i], "--file_size")) {
params.file_size = atof(argv[++i]);
} else {
fprintf(stderr, "bad arg %s\n", argv[i]);
exit(1);
}
}
#if 0
HOST_ARRIVAL *h = new HOST_ARRIVAL;
h->t = 0;
sim.insert(h);
#endif
#if 0
for (int i=0; i<500; i++) {
sim.insert(new SIM_HOST);
}
#endif
SIM_FILE* dfile = new SIM_FILE(params.file_size);
dfile->policy = policy;
sim.insert(dfile);
sim.simulate(params.sim_duration);
printf("%s: simulation finished\n", now_str());
dfile->print_stats(sim.now);
}
示例8: assign
// if there aren't enough replicas of this chunk,
// pick new hosts and start downloads
//
int CHUNK::assign() {
if (!present_on_server) return 0;
VDA_FILE_AUX* fp = parent->dfile;
while ((int)(hosts.size()) < fp->policy.replication) {
#if 0
if (parent->dfile->unused_hosts.size() == 0) {
die("no more hosts!\n");
}
set<SIM_HOST*>::iterator i = fp->unused_hosts.begin();
SIM_HOST* h = *i;
fp->unused_hosts.erase(i);
#else
SIM_HOST* h = new SIM_HOST;
sim.insert(h);
#endif
CHUNK_ON_HOST *c = new CHUNK_ON_HOST();
sprintf(c->physical_file_name, "chunk %s on host %d", name, h->id);
#ifdef EVENT_DEBUG
printf("%s: assigning chunk %s to host %d\n", now_str(), name, h->id);
#endif
c->host = h;
c->chunk = this;
h->chunks.insert(c);
hosts.insert(c);
c->start_download();
}
return 0;
}
示例9: start_download
void CHUNK_ON_HOST::start_download() {
transfer_in_progress = true;
transfer_wait = true;
t = sim.now + drand()*p.connect_interval;
#ifdef EVENT_DEBUG
printf("%s: waiting to start download of %s\n", now_str(), name);
#endif
sim.insert(this);
}
示例10: handle
// transfer or transfer wait has finished
//
void CHUNK_ON_HOST::handle() {
if (transfer_wait) {
transfer_wait = false;
if (present_on_host) {
#ifdef EVENT_DEBUG
printf("%s: starting upload of %s\n", now_str(), physical_file_name);
#endif
chunk->parent->dfile->upload_rate.sample_inc(
host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
} else {
#ifdef EVENT_DEBUG
printf("%s: starting download of %s\n", now_str(), physical_file_name);
#endif
chunk->parent->dfile->download_rate.sample_inc(
host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
}
t = sim.now + chunk->size/host->transfer_rate;
sim.insert(this);
return;
}
transfer_in_progress = false;
if (present_on_host) {
// it was an upload
#ifdef EVENT_DEBUG
printf("%s: upload of %s completed\n", now_str(), physical_file_name);
#endif
chunk->parent->dfile->upload_rate.sample_inc(
-host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
chunk->upload_complete();
} else {
present_on_host = true;
#ifdef EVENT_DEBUG
printf("%s: download of %s completed\n", now_str(), physical_file_name);
#endif
chunk->parent->dfile->download_rate.sample_inc(
-host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
chunk->download_complete();
}
}
示例11: remove
void CHUNK_ON_HOST::remove() {
if (transfer_in_progress) {
sim.remove(this);
if (!transfer_wait) {
if (present_on_host) {
chunk->parent->dfile->upload_rate.sample_inc(
-host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
} else {
chunk->parent->dfile->download_rate.sample_inc(
-host->transfer_rate,
chunk->parent->dfile->collecting_stats(),
sim.now
);
}
}
}
}