/* * Used to get a full node object out of the database. If no matching item is in the database no one will be created (use updateNode). * Usefull for comparision to current states and updates. * Also includes the nodes id, which is needed for further querying. */ Node * DBLayer::getNodeByHWID( string hwid ) { // Create a new transaction. It gets automatically destroyed at the end of this funtion. work selectAction( *conn, "Select Transaction" ); // Perform a select result resultSelect = selectAction.exec( ( "SELECT node_id FROM nodes WHERE hardware_uid='" + selectAction.esc( hwid ) + "'" ) ); selectAction.commit(); // Check if there is only one result if( resultSelect.size() == 1 ) { // Create Node and save the results unsigned int id = 0; Node * returns = new Node( hwid ); // Check if results are sane (and convert them) if( !resultSelect[0]["node_id"].to( id ) ) { throw integretyError; return NULL; } returns->node_id = id; return returns; } else { // Not found return NULL; } }
// Sample one possible sequence of future events, up to 'dfr' cycles. reward_t SearchNode::sample(Agent &agent, unsigned int dfr) { double newReward; if (dfr == 0) { return 0; } else if (m_chance_node) { // Generate whole observation-reward percept, // according to the agent's model of the environment. percept_t obs; percept_t rew; agent.genPerceptAndUpdate(obs, rew); // Calculate the index of whole percept percept_t percept = (rew << agent.numObsBits()) | obs; if (m_child.count(percept) == 0) { m_child[percept] = new SearchNode(false, agent.numActions()); } newReward = rew + m_child[percept]->sample(agent, dfr - 1); } else if (m_visits == 0) { newReward = playout(agent, dfr); } else { // Select an action to sample. action_t action = selectAction(agent, dfr); agent.modelUpdate(action); newReward = m_child[action]->sample(agent, dfr); } // Update our estimate of the future reward. m_mean = (1.0 / (double) (m_visits + 1)) * (newReward + m_visits * m_mean); ++m_visits; return newReward; }
/* * Returns a Filesystem identified by its unique identifier. * Filesystems are not node dependent. */ Filesystem * DBLayer::getFilesystemByUID( string uid ) { // Create a new transaction. It gets automatically destroyed at the end of this funtion. work selectAction( *conn, "Select Transaction" ); // Perform a select result resultSelect = selectAction.exec( "SELECT fs_id FROM Filesystems WHERE uid='" + selectAction.esc( uid ) + "'" ); selectAction.commit(); // Check if there is only one result if( resultSelect.size() == 1 ) { // Create Filesystem and save the results unsigned int id; Filesystem * returns = new Filesystem( uid ); // Check if results are sane (and convert them) if( !resultSelect[0]["fs_id"].to( id ) ) { throw integretyError; return NULL; } returns->Filesystem_id = id; return returns; } else { // Something went wrong //throw integretyError; return NULL; } }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentSeveralActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QVERIFY(toolButton->isEnabled()); QVERIFY(toolButton->autoRaise()); QCOMPARE((int)toolButton->focusPolicy(), (int)Qt::NoFocus); QCOMPARE(toolButton->defaultAction(), (QAction*)&selectAction); QCOMPARE(toolButton->actions().count(), 4); QCOMPARE(toolButton->actions().at(0)->text(), QString("selectAction")); QCOMPARE(toolButton->actions().at(1)->text(), QString("action1")); QCOMPARE(toolButton->actions().at(2)->text(), QString("action2")); QCOMPARE(toolButton->actions().at(3)->text(), QString("action3")); }
void AtariNoGeomExperiment::runAtariEpisode(shared_ptr<NEAT::GeneticIndividual> individual) { // Reset the game ale.reset_game(); while (!ale.game_over()) { // Set value of all nodes to zero substrate.reinitialize(); substrate.dummyActivation(); setSubstrateValues(); // Propagate values through the ANN substrate.update(); //printLayerInfo(); // Choose which action to take Action action = selectAction(*visProc); ale.act(action); } cout << "Game ended in " << ale.frame << " frames with score " << ale.game_score << endl; // Give the reward to the agent individual->reward(ale.game_score); }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentRemoveActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QAction* action1 = new QAction("action1", &selectAction); selectAction.addAction(action1); QAction* action2 = new QAction("action2", &selectAction); selectAction.addAction(action2); QAction* action3 = new QAction("action3", &selectAction); selectAction.addAction(action3); delete selectAction.removeAction(action1); delete selectAction.removeAction(action2); delete selectAction.removeAction(action3); QVERIFY(!widget->isEnabled()); QCOMPARE(widget->actions().count(), 1); QCOMPARE(widget->actions().at(0)->text(), QString("selectAction")); }
void AtariFTNeatExperiment::runAtariEpisode(shared_ptr<NEAT::GeneticIndividual> individual) { // Reset the game ale.reset_game(); while (!ale.game_over()) { // Set value of all nodes to zero substrate.reinitialize(); substrate.dummyActivation(); // Set substrate value for all objects (of a certain size) setSubstrateObjectValues(*visProc); // Set substrate value for self setSubstrateSelfValue(*visProc); // Propagate values through the ANN // This is necessary to fully propagate through the different layers substrate.updateFixedIterations(2); //printLayerInfo(); // Choose which action to take Action action = selectAction(*visProc); ale.act(action); } cout << "Game ended in " << ale.frame << " frames with score " << ale.game_score << endl; // Give the reward to the agent individual->reward(ale.game_score); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_plugins(PluginRegistry::instance()) { ui->setupUi(this); connect(ui->actionEdit, SIGNAL(triggered(bool)), this, SLOT(openEdit())); connect(ui->actionRecord, SIGNAL(triggered(bool)), this, SLOT(openRecord())); connect(ui->actionPlugins, SIGNAL(triggered(bool)), this, SLOT(openPlugins())); connect(ui->recordPage, SIGNAL(recordFinished()), this, SLOT(editRequests())); QToolButton *openButton = static_cast<QToolButton *>(ui->toolBar->widgetForAction(ui->actionOpen)); openButton->setPopupMode(QToolButton::MenuButtonPopup); QAction *openSeparator = new QAction(this); openSeparator->setSeparator(true); openButton->addAction(openSeparator); QToolButton *saveButton = static_cast<QToolButton *>(ui->toolBar->widgetForAction(ui->actionSave)); saveButton->setPopupMode(QToolButton::MenuButtonPopup); saveButton->addAction(ui->actionSaveAs); connect(ui->actionNew, SIGNAL(triggered(bool)), ui->editPage, SLOT(newProject())); connect(ui->actionOpen, SIGNAL(triggered(bool)), this, SLOT(loadProject())); connect(ui->actionSave, SIGNAL(triggered(bool)), this, SLOT(saveProject())); connect(ui->actionSaveAs, SIGNAL(triggered(bool)), this, SLOT(saveProjectAs())); selectAction(ui->actionEdit); updateOpenMenu(); connect(&m_plugins, SIGNAL(toolPluginLoaded(QObject *)), ui->editPage, SLOT(addToolToToolbar(QObject *))); PostMonster::APIFunctions api; api.evalScript = WorkEngine::evalScript; api.serializeRequest = Common::serializeRequest; api.deserializeRequest = Common::deserializeRequest; api.serializeResponse = Common::serializeResponse; api.deserializeResponse = Common::deserializeResponse; api.defaultEncodings = Common::encodings; api.dpiScaleFactor = Common::dpiScaleFactor; m_plugins.loadPlugins(api); if (m_plugins.tool("http")) { PostMonster::HttpToolPluginInterface *httpTool = static_cast<PostMonster::HttpToolPluginInterface *>(m_plugins.tool("http")); ui->editPage->setRequestsModel(httpTool, &m_requestsModel); ui->recordPage->setRequestsModel(httpTool, &m_requestsModel); } connect(ui->editPage, &EditForm::debugStatusChanged, ui->actionNew, &QAction::setDisabled); connect(ui->editPage, &EditForm::debugStatusChanged, ui->actionOpen, &QAction::setDisabled); connect(ui->editPage, &EditForm::debugStatusChanged, ui->actionRecord, &QAction::setDisabled); foreach (QToolBar *toolBar, findChildren<QToolBar *>()) { toolBar->setIconSize(toolBar->iconSize() * Common::dpiScaleFactor()); }
void SwitchAction::update(float dt){ if (selectedAction == -1){ selectedAction = selectAction(); } else { if (!actionList[selectedAction]->finished){ actionList[selectedAction]->update(dt); } else finished = true; } }
/* * Returns a list of all storage devices which are connected to a node (specified by node_id). * To get the node_id use getNodeByHWID. */ list<StorageDevice> * DBLayer::getAllStorageDevicesByNode( unsigned int node_id ) { // Create a new transaction. It gets automatically destroyed at the end of this funtion. work selectAction( *conn, "Select Transaction" ); // Perform a select. The result will be automatically destroyed. result resultSelect = selectAction.exec( "SELECT device_id, model_name, local_address FROM StorageDevices WHERE node_id=" + selectAction.esc( to_string( node_id ) ) + "" ); selectAction.commit(); // Check if there's at least one result if( resultSelect.size() > 0 ) { // Create Node and save the results unsigned int device_id; string model_name; string local_address; // Allocate space list<StorageDevice>* returns; returns = new list<StorageDevice>; // TODO: Will this be freed on the end of the function? StorageDevice * tempDevice; // Go thorugh all results for( result::size_type i = 0; i != resultSelect.size(); ++i ) { // Sanity checks and convertions if( !resultSelect[i]["device_id"].to( device_id ) ) { throw integretyError; return NULL; } if( !resultSelect[i]["model_name"].to( model_name ) ) { throw integretyError; return NULL; } if( !resultSelect[i]["local_address"].to( local_address ) ) { throw integretyError; return NULL; } // Create a new object, fill it and push it into the list tempDevice = new StorageDevice(); tempDevice->device_id = device_id; tempDevice->model_name = model_name; tempDevice->local_address = local_address; tempDevice->node_id = node_id; returns->push_back( *tempDevice ); } return returns; } else { // No results. Return NULL. return NULL; } }
void KSelectAction_UnitTest::testSetWhatsThisBeforeRequestingComboBoxWidget() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::ComboBoxMode); selectAction.setWhatsThis("Test"); QWidget parent; QWidget* widget = selectAction.requestWidget(&parent); QVERIFY(widget); KComboBox* comboBox = qobject_cast<KComboBox*>(widget); QVERIFY(comboBox); QCOMPARE(comboBox->whatsThis(), QString("Test")); }
void KSelectAction_UnitTest::testRequestWidgetComboBoxModeWidgetParent() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::ComboBoxMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); KComboBox* comboBox = qobject_cast<KComboBox*>(widget); QVERIFY(comboBox); QVERIFY(!comboBox->isEnabled()); }
void KSelectAction_UnitTest::testSetToolTipBeforeRequestingComboBoxWidget() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::ComboBoxMode); selectAction.setToolTip("Test"); selectAction.setEnabled(false); // also test disabling the action QWidget parent; QWidget* widget = selectAction.requestWidget(&parent); QVERIFY(widget); KComboBox* comboBox = qobject_cast<KComboBox*>(widget); QVERIFY(comboBox); QCOMPARE(comboBox->toolTip(), QString("Test")); QCOMPARE(comboBox->isEnabled(), false); }
void KSelectAction_UnitTest::testSetToolTipBeforeRequestingToolButtonWidget() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.setToolTip("Test"); QToolBar toolBar; //Don't use requestWidget, as it needs a releaseWidget when used in MenuMode //(in ComboBoxMode the widget is released automatically when it is //destroyed). When the action is added to the QToolBar, it requests and //releases the widget as needed. toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QCOMPARE(toolButton->toolTip(), QString("Test")); }
void KSelectAction_UnitTest::testChildActionStateChangeComboMode() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::ComboBoxMode); QWidget parent; QWidget* widget = selectAction.requestWidget(&parent); KComboBox* comboBox = qobject_cast<KComboBox*>(widget); QVERIFY(comboBox); const QString itemText = "foo"; KAction* childAction = selectAction.addAction(itemText); QCOMPARE(comboBox->itemText(0), itemText); childAction->setEnabled(false); // There's no API for item-is-enabled, need to go via the internal model like kselectaction does... QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model()); QVERIFY(model); QVERIFY(!model->item(0)->isEnabled()); // Now remove the action selectAction.removeAction(childAction); QCOMPARE(comboBox->count(), 0); }
SWDialog::SWDialog(QWidget* parent) : QDialog(parent) { setupUi(this); cfg = new SWConfig(); languageComboBox->addItems(cfg->getAvailableLanguagesList()); languageChange(); resize(minimumSizeHint()); // signals and slots connections connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(okButton_pressed())); connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(cancelButton_pressed())); connect(styleCheckBox, SIGNAL(toggled(bool)), languageComboBox, SLOT(setDisabled(bool))); selectAction(cfg->action); styleCheckBox->setChecked(cfg->useStyle); languageComboBox->setCurrentIndex(cfg->currentLanguage); }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentAddActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QVERIFY(!widget->isEnabled()); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QVERIFY(widget->isEnabled()); QCOMPARE(widget->actions().count(), 4); QCOMPARE(widget->actions().at(0)->text(), QString("selectAction")); QCOMPARE(widget->actions().at(1)->text(), QString("action1")); QCOMPARE(widget->actions().at(2)->text(), QString("action2")); QCOMPARE(widget->actions().at(3)->text(), QString("action3")); }
/* * Used to update a StorageDevice. * The device is identified by its node_id and device_id in the struct. * If the corresponding device does not exist in the database it will be created. */ void DBLayer::updateStorageDevice( StorageDevice * new_StorageDevice ) { if( DBLayer::getStorageDeviceByNodeAndDevice( new_StorageDevice->node_id, new_StorageDevice->device_id ) != NULL ) { // Entry already exists. Perform an update. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work updateAction( *conn, "Update Transaction" ); // Perform the update updateAction.exec( "UPDATE StorageDevices SET model_name='" + updateAction.esc( to_string( new_StorageDevice->model_name ) ) + "', local_address='" + updateAction.esc( to_string( new_StorageDevice->local_address ) ) + "' WHERE node_id=" + updateAction.esc( to_string( new_StorageDevice->node_id ) ) + " AND device_id=" + updateAction.esc( to_string( new_StorageDevice->device_id ) ) + "" ); updateAction.commit(); } else { // Entry does not exists. Perform an insert.nschen, die auf Code starren. Es sind Frauen anwe // Create a new transaction. It gets automatically destroyed at the end of this funtion. work insertAction( *conn, "Insert Transaction" ); // Perform the insert insertAction.exec( "INSERT INTO StorageDevices (model_name, local_address, node_id) VALUES ('" + insertAction.esc( to_string( new_StorageDevice->model_name ) ) + "', '" + insertAction.esc( to_string( new_StorageDevice->local_address ) ) + "', '" + insertAction.esc( to_string( new_StorageDevice->node_id ) ) + "')" ); insertAction.commit(); // Update new_StorageDevice unsigned int id = 0; work selectAction( *conn, "Select Transaction" ); result resultSelect = selectAction.exec( "SELECT device_id FROM StorageDevices WHERE model_name='" + insertAction.esc( to_string( new_StorageDevice->model_name ) ) + "' AND local_address = '" + insertAction.esc( to_string( new_StorageDevice->local_address ) ) + "' AND node_id = '" + insertAction.esc( to_string( new_StorageDevice->node_id ) ) + "'" ); selectAction.commit(); // Check if there is only one result if( resultSelect.size() == 1 ) { // Check if results are sane (and convert them) if( !resultSelect[0]["device_id"].to( id ) ) throw integretyError; } else { // Something went wrong //throw integretyError; } new_StorageDevice->device_id = id; } }
void QsciEditor::setupActions() { cutAct = new QAction( QIcon::fromTheme( "edit-cut" ), "Cu&t", this ); cutAct->setStatusTip( "Cut the selected text" ); cutAct->setShortcut( tr( "Ctrl+X" ) ); copyAct = new QAction( QIcon::fromTheme( "edit-copy" ), "&Copy", this ); copyAct->setStatusTip( "Copy the selected text" ); copyAct->setShortcut( tr( "Ctrl+C" ) ); pasteAct = new QAction( QIcon::fromTheme( "edit-paste" ), "&Paste", this ); pasteAct->setStatusTip( "Paste the text on the clipboard" ); pasteAct->setShortcut( tr( "Ctrl+V" ) ); deleteAct = new QAction( QIcon::fromTheme( "edit-delete" ), "&Delete", this ); deleteAct->setStatusTip( "Delete the selected Text" ); deleteAct->setShortcut( tr( "Delete" ) ); selectAct = new QAction( QIcon::fromTheme( "edit-select-all" ), "Select &All", this ); selectAct->setStatusTip( "Select all the text" ); selectAct->setShortcut( tr( "Ctrl+A" ) ); deselectAct = new QAction( QIcon(), "Deselect &All", this ); deselectAct->setStatusTip( "Deselect all the text" ); deselectAct->setShortcut( tr( "Ctrl+Shift+A" ) ); undoAct = new QAction( QIcon::fromTheme( "edit-undo" ), "&Undo", this ); undoAct->setStatusTip( "Undo the last change" ); undoAct->setShortcut( tr( "Ctrl+Z" ) ); redoAct = new QAction( QIcon::fromTheme( "edit-redo" ), "&Redo", this ); redoAct->setStatusTip( "Redo the undone change" ); redoAct->setShortcut( tr( "Ctrl+Y" ) ); searchAct = new QAction( QIcon::fromTheme( "edit-find" ), "&Search", this ); searchAct->setStatusTip( "Search the document" ); searchAct->setShortcut( tr( "Ctrl+F" ) ); replaceAct = new QAction( QIcon::fromTheme( "edit-find-replace" ), "&Replace", this ); replaceAct->setStatusTip( "Replace text in the document" ); replaceAct->setShortcut( tr( "Ctrl+R" ) ); changeFontAct = new QAction( QIcon::fromTheme( "preferences-desktop-font" ), "Change &Font", this ); changeFontAct->setStatusTip( "Change the font of the document" ); changeFontAct->setShortcut( tr( "Ctrl+Shift+F" ) ); toggleCaseAct = new QAction( "T&oggle Case of Selection", this ); toggleCaseAct->setStatusTip( "Toggle the case of the selected text" ); toggleCaseAct->setShortcut( tr( "Ctrl+Alt+U" ) ); connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( showCustomMenu( const QPoint& ) ) ); connect( cutAct, SIGNAL( triggered() ), this, SLOT( cutAction() ) ); connect( copyAct, SIGNAL( triggered() ), this, SLOT( copyAction() ) ); connect( pasteAct, SIGNAL( triggered() ), this, SLOT( pasteAction() ) ); connect( deleteAct, SIGNAL( triggered() ), this, SLOT( deleteAction() ) ); connect( undoAct, SIGNAL( triggered() ), this, SLOT( undoAction() ) ); connect( redoAct, SIGNAL( triggered() ), this, SLOT( redoAction() ) ); connect( selectAct, SIGNAL( triggered() ), this, SLOT( selectAction() ) ); connect( deselectAct, SIGNAL( triggered() ), this, SLOT( deselectAction() ) ); connect( changeFontAct, SIGNAL( triggered() ), this, SLOT( changeFont() ) ); connect( toggleCaseAct, SIGNAL( triggered() ), this, SLOT( toggleCase() ) ); connect( searchAct, SIGNAL( triggered() ), this, SLOT( showSearch() ) ); connect( this, SIGNAL( linesChanged() ), this, SLOT( resizeMargins() ) ); addAction( cutAct ); addAction( copyAct ); addAction( pasteAct ); addAction( deleteAct ); addAction( selectAct ); addAction( deselectAct ); addAction( undoAct ); addAction( redoAct ); addAction( searchAct ); addAction( replaceAct ); addAction( changeFontAct ); addAction( toggleCaseAct ); /* Change keyBindings */ SendScintilla( SCI_ASSIGNCMDKEY, SCK_DOWN + ( SCMOD_CTRL << 16 ), SCI_PARADOWN ); SendScintilla( SCI_ASSIGNCMDKEY, SCK_UP + ( SCMOD_CTRL << 16 ), SCI_PARAUP ); SendScintilla( SCI_ASSIGNCMDKEY, SCK_DOWN + ( SCMOD_ALT << 16 ), SCI_LINESCROLLDOWN ); SendScintilla( SCI_ASSIGNCMDKEY, SCK_UP + ( SCMOD_ALT << 16 ), SCI_LINESCROLLUP ); /* Remove Ctrl+D as duplicate line */ SendScintilla( SCI_CLEARCMDKEY, 68 + ( SCMOD_CTRL << 16 ) ); };
int main() { //learning factor const double alpha = 0.5; //discount factor const double gamma = 0.5; const double deltatime = 0.05; const double mass = 0.5; const double length = 0.08; const int angle_bins = 100; const int velocity_bins = 50; const int torque_bins = 9; const double max_angle = M_PI; const double max_velocity = 10; const double max_torque = 4; Environment* env = new Environment(0, 0, 0, max_torque, 0, deltatime, mass, length, gamma); //seed rng std::srand(static_cast<unsigned int>(std::time(NULL))); //create the possible actions as well as the chosen action float chosen_action = 1; // rip f float actions[torque_bins]; for (int i = 0; i < (max_torque*2)+1 ; ++i) { actions[i] = static_cast<float>(-max_torque+i); } //create a priority queue to copy to all the state space priority queues PriorityQueue<float, double> initiator_queue(MAX); for (int i = 0; i < torque_bins; ++i) { initiator_queue.enqueueWithPriority(actions[i], 0); } //create the state space StateSpace space(initiator_queue, angle_bins, velocity_bins, torque_bins, max_angle, max_velocity, max_torque); //state objects State current_state(0, 0, 0); State old_state(0, 0, 0); // std::ofstream file("output.txt"); // file.precision(16); // file << "Trialno" << " " << "Time" << " " << "Theta" << " " << "Thetadot" << " " << "Torque" << std::endl; double trialno = 1; unsigned long i=0; while (true) { current_state.theta = env->getTheta(); current_state.theta_dot = env->getThetadot(); current_state.torque = env->getTorque(); std::cout << "State Read" << std::endl; updateQ(space, chosen_action, old_state, current_state, alpha, gamma); if (std::abs(current_state.theta_dot) > 5) { env->resetPendulum(); std::cout<<"->unsuccessful trial\n"; trialno++; i = 0; continue; } old_state = current_state; chosen_action = selectAction(space[current_state],i); std::cout << "Action Selected" << std::endl; env->setTorque(chosen_action); env->propagate(); std::cout << "Environment Propagated\n" << std::endl; // file << trialno << " " << env->getTime() << " " << current_state.theta << " " << current_state.theta_dot << " " << current_state.torque << std::endl; ++i; } // file.close(); delete env; return 1; }
/* ============================================================================= * client_run * -- Execute list operations on the database * ============================================================================= */ void client_run (void* argPtr) { TM_THREAD_ENTER(); long myId = thread_getId(); client_t* clientPtr = ((client_t**)argPtr)[myId]; manager_t* managerPtr = clientPtr->managerPtr; random_t* randomPtr = clientPtr->randomPtr; long numOperation = clientPtr->numOperation; long numQueryPerTransaction = clientPtr->numQueryPerTransaction; long queryRange = clientPtr->queryRange; long percentUser = clientPtr->percentUser; long* types = (long*)P_MALLOC(numQueryPerTransaction * sizeof(long)); long* ids = (long*)P_MALLOC(numQueryPerTransaction * sizeof(long)); long* ops = (long*)P_MALLOC(numQueryPerTransaction * sizeof(long)); long* prices = (long*)P_MALLOC(numQueryPerTransaction * sizeof(long)); long i; for (i = 0; i < numOperation; i++) { long r = random_generate(randomPtr) % 100; action_t action = selectAction(r, percentUser); switch (action) { case ACTION_MAKE_RESERVATION: { long maxPrices[NUM_RESERVATION_TYPE] = { -1, -1, -1 }; long maxIds[NUM_RESERVATION_TYPE] = { -1, -1, -1 }; long n; long numQuery = random_generate(randomPtr) % numQueryPerTransaction + 1; long customerId = random_generate(randomPtr) % queryRange + 1; for (n = 0; n < numQuery; n++) { types[n] = random_generate(randomPtr) % NUM_RESERVATION_TYPE; ids[n] = (random_generate(randomPtr) % queryRange) + 1; } bool_t isFound = FALSE; TM_BEGIN(); for (n = 0; n < numQuery; n++) { long t = types[n]; long id = ids[n]; long price = -1; switch (t) { case RESERVATION_CAR: if (MANAGER_QUERY_CAR(managerPtr, id) >= 0) { price = MANAGER_QUERY_CAR_PRICE(managerPtr, id); } break; case RESERVATION_FLIGHT: if (MANAGER_QUERY_FLIGHT(managerPtr, id) >= 0) { price = MANAGER_QUERY_FLIGHT_PRICE(managerPtr, id); } break; case RESERVATION_ROOM: if (MANAGER_QUERY_ROOM(managerPtr, id) >= 0) { price = MANAGER_QUERY_ROOM_PRICE(managerPtr, id); } break; default: assert(0); } if (price > maxPrices[t]) { maxPrices[t] = price; maxIds[t] = id; isFound = TRUE; } } /* for n */ if (isFound) { MANAGER_ADD_CUSTOMER(managerPtr, customerId); } if (maxIds[RESERVATION_CAR] > 0) { MANAGER_RESERVE_CAR(managerPtr, customerId, maxIds[RESERVATION_CAR]); } if (maxIds[RESERVATION_FLIGHT] > 0) { MANAGER_RESERVE_FLIGHT(managerPtr, customerId, maxIds[RESERVATION_FLIGHT]); } if (maxIds[RESERVATION_ROOM] > 0) { MANAGER_RESERVE_ROOM(managerPtr, customerId, maxIds[RESERVATION_ROOM]); } TM_END(); break; } case ACTION_DELETE_CUSTOMER: { long customerId = random_generate(randomPtr) % queryRange + 1; TM_BEGIN(); long bill = MANAGER_QUERY_CUSTOMER_BILL(managerPtr, customerId); if (bill >= 0) { MANAGER_DELETE_CUSTOMER(managerPtr, customerId); } TM_END(); break; } case ACTION_UPDATE_TABLES: { long numUpdate = random_generate(randomPtr) % numQueryPerTransaction + 1; long n; for (n = 0; n < numUpdate; n++) { types[n] = random_generate(randomPtr) % NUM_RESERVATION_TYPE; ids[n] = (random_generate(randomPtr) % queryRange) + 1; ops[n] = random_generate(randomPtr) % 2; if (ops[n]) { prices[n] = ((random_generate(randomPtr) % 5) * 10) + 50; } } TM_BEGIN(); for (n = 0; n < numUpdate; n++) { long t = types[n]; long id = ids[n]; long doAdd = ops[n]; if (doAdd) { long newPrice = prices[n]; switch (t) { case RESERVATION_CAR: MANAGER_ADD_CAR(managerPtr, id, 100, newPrice); break; case RESERVATION_FLIGHT: MANAGER_ADD_FLIGHT(managerPtr, id, 100, newPrice); break; case RESERVATION_ROOM: MANAGER_ADD_ROOM(managerPtr, id, 100, newPrice); break; default: assert(0); } } else { /* do delete */ switch (t) { case RESERVATION_CAR: MANAGER_DELETE_CAR(managerPtr, id, 100); break; case RESERVATION_FLIGHT: MANAGER_DELETE_FLIGHT(managerPtr, id); break; case RESERVATION_ROOM: MANAGER_DELETE_ROOM(managerPtr, id, 100); break; default: assert(0); } } } TM_END(); break; } default: assert(0); } /* switch (action) */ } /* for i */ TM_THREAD_EXIT(); }
bool AddConstraintHandler::handleURI(URI& uri) { if (uri.action != "add_constraint") return false; wxString type = uri.getParam("type"); // pk, fk, check, unique Table* t = extractMetadataItemFromURI<Table>(uri); wxWindow* w = getParentWindow(uri); if (!t || !w) return true; // Find first available constraint name: DatabasePtr db = t->getDatabase(); wxString prefix = type + "_" + t->getName_(); wxString stmt( "select rdb$constraint_name from rdb$relation_constraints " "where rdb$relation_name = '" + t->getName_() + "' and rdb$constraint_name starting with '" + prefix + "' order by 1"); wxString default_value; wxArrayString constraintNames(db->loadIdentifiers(stmt)); for (int i = 0; ; ++i) { default_value = prefix + wxString::Format("_%d", i); if (constraintNames.Index(default_value, false) == wxNOT_FOUND) break; } wxString cname = ::wxGetTextFromUser(_("Enter constraint name"), _("Adding new table constraint"), default_value, w); if (cname.IsEmpty()) // cancel return true; wxString sql = "alter table " + t->getQuotedName() + "\nadd constraint " + Identifier::userString(cname); if (type == "PK") { wxString columnlist = selectRelationColumns(t, w); if (columnlist.IsEmpty()) // cancel return true; sql += "\nprimary key (" + columnlist + ")"; } else if (type == "FK") { wxString columnlist = selectRelationColumns(t, w); if (columnlist == "") return true; TablePtr ref = selectTable(t->getDatabase(), w); if (!ref) return true; wxString refcolumnlist = selectRelationColumns(ref.get(), w); if (refcolumnlist == "") return true; sql += "\nforeign key (" + columnlist + ") \nreferences " + ref->getQuotedName() + " (" + refcolumnlist + ")"; wxString action = selectAction(_("update"), w); if (action == "CANCEL") return true; else if (action != "RESTRICT") sql += "\non update " + action + " "; action = selectAction(_("delete"), w); if (action == "CANCEL") return true; else if (action != "RESTRICT") sql += "\non delete " + action + " "; } else if (type == "CHK") { wxString source; if (!GetMultilineTextFromUser(w, _("Enter check condition"), source)) return true; sql += "\ncheck (" + source + ")"; } else if (type == "UNQ") { wxString columnlist = selectRelationColumns(t, w); if (columnlist.IsEmpty()) // cancel return true; sql += "\nunique (" + columnlist + ")"; } else { ::wxMessageBox(_("Unknown constraint type"), _("Error."), wxOK | wxICON_ERROR); return true; } execSql(w, "", db, sql, true); // true = commit + close at once return true; }