Created
December 27, 2012 20:11
-
-
Save kcuzner/4391549 to your computer and use it in GitHub Desktop.
A very very basic test of the simulation engine multiplying two numbers together.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "defaultblockfactory.h" | |
#include "system/systemblocks.h" | |
#include "model.h" | |
#include "simpleengine.h" | |
int main(int argc, char** argv) | |
{ | |
//create a model using the default block factory | |
boost::shared_ptr<IModel> model(new Model(DefaultBlockFactory::getInstance())); | |
//create an engine for that model | |
boost::shared_ptr<IEngine> engine(new SimpleEngine(model, 20, 0.1)); | |
//initialize the block factory to use the system blocks | |
boost::shared_ptr<IBlockCollection> systemBlocks(new System::SystemBlocks()); | |
systemBlocks->declareToFactory(DefaultBlockFactory::getInstance()); | |
//create a static variable block with the value 5.5 | |
boost::shared_ptr<IBlock> block = model->createBlock("Var", "Static"); | |
boost::shared_ptr<std::vector<double> > value(new std::vector<double>()); | |
value->push_back(5.5); | |
block->setOption(engine->getContext().get(), "Value", value); | |
//create another static variable block with the value 2.0 | |
boost::shared_ptr<IBlock> block2 = model->createBlock("Var", "Static"); | |
value = boost::shared_ptr<std::vector<double> >(new std::vector<double>()); | |
value->push_back(2.0); | |
block2->setOption(engine->getContext().get(), "Value", value); | |
//create a multiplier block | |
boost::shared_ptr<IBlock> block3 = model->createBlock("Math", "Multiply"); | |
//connect the output of the 5.5 variable to the 1st input of the multiplier block | |
block->connect("Output", block3, "Multiplicand 1", false); | |
//connect the output of the 2.0 variable to the 2nd input of the multiplier block | |
block2->connect("Output", block3, "Multiplicand 2", false); | |
block = model->addExit("Result"); | |
//connect the product to the exit called result | |
block3->connect("Product", block, IEXITBLOCK_INPUT_NAME, false); | |
engine->run(); | |
std::cout << "Result: " << model->getExits().at("Result")->getCurrentValue(engine->getContext().get())->at(0) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment