Пример #1
0
	/**
	 * Compute a vector of maximal levels and store information about states.
	 */
	void computeBoundaries() {
		// Compute naive bounds.
		for (const SpecieID ID : cscope(model.species)) {
			// Maximal values of species
			names.push_back(model.species[ID].name);
			maxes.push_back(model.species[ID].max_value);
			mins.push_back(0);
		}

		// Add experiment constraints.
		ConstraintParser * cons_pars = new ConstraintParser(model.species.size(), ModelTranslators::getMaxLevel(model));
		cons_pars->addBoundaries(maxes, true);
		cons_pars->applyFormula(ModelTranslators::getAllNames(model), property.getExperiment());
		cons_pars->status();

		// Compute refined boundaries.
		mins = cons_pars->getBounds(false);
		maxes = cons_pars->getBounds(true);
		rng::transform(maxes, mins, back_inserter(range_size), [](const ActLevel max, const ActLevel min) {
			return max - min + 1;
		});
	}
Пример #2
0
void
dmz::JsExtV8Input::receive_mouse_event (
      const Handle Channel,
      const InputEventMouse &Value) {

   if (_v8Context.IsEmpty () == false) {

      v8::Context::Scope cscope(_v8Context);
      v8::HandleScope scope;

      V8Object event = v8::Object::New ();

      event->Set (_sourceStr, v8::Integer::New (Value.get_source_handle ()));

      const int Argc (3);
      V8Value argv[Argc];
      argv[0] = v8::Integer::New (Channel);
      argv[1] = event;

      _do_all_callbacks (Argc, argv, _mouseTable);
   }
}
Пример #3
0
void
dmz::JsExtV8Input::receive_data_event (
      const Handle Channel,
      const Handle Source,
      const Data &Value) {

   if ((_v8Context.IsEmpty () == false) && _runtime) {

      v8::Context::Scope cscope(_v8Context);
      v8::HandleScope scope;

      V8Object event = v8::Object::New ();

      const int Argc (4);
      V8Value argv[Argc];
      argv[0] = v8::Integer::New (Channel);
      argv[1] = v8::Integer::New (Source);
      argv[2] = _runtime->create_v8_data (&Value);

      _do_all_callbacks (Argc, argv, _dataTable);
   }
}
Пример #4
0
// Input Observer Interface
void
dmz::JsExtV8Input::update_channel_state (const Handle Channel, const Boolean State) {

   if (State) { _active.add (Channel); }
   else { _active.remove (Channel); }

   CallbackTable *ct = _stateTable.lookup (Channel);

   if (ct && (_v8Context.IsEmpty () == false)) {

      v8::Context::Scope cscope(_v8Context);
      v8::HandleScope scope;

      const int Argc (3);
      V8Value argv[Argc];
      argv[0] = v8::Integer::NewFromUnsigned (Channel);
      argv[1] = v8::Boolean::New (State);

      HandleContainer called;
      _do_callback (Argc, argv, *ct, called);
   }
}
dmz::V8Value
dmz::JsModuleUiV8QtBasic::create_v8_qlistwidgetitem (QListWidgetItem *value) {

   v8::Context::Scope cscope (_state.context);
   v8::HandleScope scope;

   V8Value result = v8::Undefined ();

   if (value) {

      V8Object obj;
      if (!_listWidgetItemCtor.IsEmpty ()) { obj = _listWidgetItemCtor->NewInstance (); }

      if (!obj.IsEmpty ()) {

         obj->SetInternalField (0, v8::External::Wrap ((void *)value));
         result = obj;
      }
   }

   return scope.Close (result);
}
Пример #6
0
void ProductBuilder::addStateTransitions(const UnparametrizedStructure & structure, const AutomatonStructure & automaton, const StateID s_BA_ID, const StateID s_KS_ID, const AutTransitionion & BA_transition, ProductStructure & product)
{
	StateID s_ID = product.computeID(s_KS_ID, s_BA_ID);

	// Add all the transient combinations for the kripke structure
	for (const size_t KS_trans_no : cscope(structure._states[s_KS_ID]))
	{
		const StateID t_KS_ID = structure._states[s_KS_ID]._transitions[KS_trans_no]._t_ID;
		if (satisfiesDeltas(structure, s_KS_ID, t_KS_ID, BA_transition._deltas_cons)) 
		{
			const TransConst & trans_const = structure._states[s_KS_ID]._transitions[KS_trans_no]._trans_const;
			const StateID t_ID = product.computeID(t_KS_ID, BA_transition._t_ID);
			product._states[s_ID]._transitions.emplace_back(TSTransitionProperty(t_ID, trans_const));
		}
	}

	// Copy stay constraints
	product._states[s_ID]._stay_const = structure._states[s_KS_ID]._stay_const;

	// Add a self-loops
	product._states[s_ID]._loops.emplace_back(product.computeID(s_KS_ID, BA_transition._t_ID));
}
Пример #7
0
	void compute(const RegInfos & reg_infos, const CompID ID, const int step_count, sqlite3pp::query & qry, map<CompID, vector<double> > & freq, map<CompID, vector<char> > & sign) 
	{
		map<Regulation, size_t> column_of_regulation;
		for (const auto & regulator : reg_infos[ID].regulators) 
		{
			for (ActLevel threshold : regulator.second) {
				string column_name = "S_" + reg_infos[regulator.first].name + "_" + to_string(threshold) + "_" + reg_infos[ID].name;
				Regulation regulation = Regulation{ reg_infos[regulator.first].ID, threshold, reg_infos[ID].ID };
				for (const size_t column_i : crange(qry.column_count())) 
				{
					string database_column = qry.column_name(column_i);

					if (database_column == column_name) 
					{
						column_of_regulation[regulation] = column_i;
					}
				}
				if (column_of_regulation.count(regulation) == 0) 
				{
					throw runtime_error("did not find the regulation " + column_name + " in the database");
				}
			}
		}

		// Compute relation to each regulation of this component, step by database rows
		for (const auto & row : qry) 
		{
			for (const auto & regulator : reg_infos[ID].regulators) 
			{
				for (size_t threshold_i : cscope(regulator.second)) 
				{
					const ActLevel threshold = regulator.second[threshold_i];
					Regulation regulation = Regulation{ reg_infos[regulator.first].ID, threshold, reg_infos[ID].ID };
					size_t column_i = column_of_regulation[regulation];
					char label = row.get<const char *>(column_i)[0];
					if (label != '0') 
					{
						freq[regulator.first][threshold_i]++;
						sign[regulator.first][threshold_i] |= label;
					}
				}
			}
		}

		for (auto & freq_pair : freq)
		{
			Statistics::normalize(step_count, freq_pair.second);
		}

		for (const auto & regulator : reg_infos[ID].regulators) 
		{
			for (size_t threshold_i : cscope(regulator.second)) 
			{
				// no active edge at all
				if (sign[regulator.first][threshold_i] == 0) 
				{
					sign[regulator.first][threshold_i] = '0';
				}
				// there were active edges and they were not either only + or only -
				else if (sign[regulator.first][threshold_i] != '+' && sign[regulator.first][threshold_i] != '-') 
				{
					sign[regulator.first][threshold_i] = '1';
				}
			}
		}
	}
Пример #8
0
int tremppi_correlations(int argc, char ** argv) 
{
	TremppiSystem::initiate("tremppi_correlations", argc, argv);
	Logging logging;

	RegInfos reg_infos;
	sqlite3pp::database db;
	vector<string> selections;
	vector<string> sels_name;
	DatabaseReader reader;
	try {
		DEBUG_LOG << "Parsing data file.";
		db = move(sqlite3pp::database((TremppiSystem::DATA_PATH / DATABASE_FILENAME).string().c_str()));
		selections = reader.getSelectionList();
		sels_name = reader.getSelectionNames();
		reg_infos = reader.readRegInfos(db);
	}
	catch (exception & e)
	{
		logging.exceptionMessage(e, 2);
	}

	// Create a report for each selection
	logging.newPhase("making report", selections.size());
	for (const size_t sel_no : cscope(selections))
	{
		Json::Value out;
		vector<sqlite3pp::query> queries;

		try
		{
			DEBUG_LOG << "Selection " + sels_name[sel_no];
			out = Report::createSetup(selections[sel_no], sels_name[sel_no]);

			for (const RegInfo & reg_info : reg_infos)
			{
				map<size_t, string> columns = sqlite3pp::func::matchingColumns(PARAMETRIZATIONS_TABLE, regex("B_" + reg_info.name), db);
				if (columns.empty())
				{
					throw runtime_error("did not find the column B_" + reg_info.name);
				}
				queries.emplace_back(DatabaseReader::selectionFilter(columns, out["setup"]["select"].asString(), db));
			}
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 3);
		}

		FunsData funs_data;
		try
		{
			DEBUG_LOG << "Computing function graph data.";
			Compute::deviation(reg_infos, out["setup"]["size"].asInt(), queries, logging, funs_data);
			Compute::correlation(reg_infos, out["setup"]["size"].asInt(), queries, logging, funs_data);
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 4);
		}
		try
		{
			DEBUG_LOG << "Writing output.";
			out["elements"] = Output::functionalData(funs_data);
			FileManipulation::writeJSON(TremppiSystem::DATA_PATH / "correlations" / (out["setup"]["s_name"].asString() + ".json"), out);
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 5);
		}

	}

	try
	{
		PythonFunctions::configure("correlations");
	}
	catch (exception & e)
	{
		logging.exceptionMessage(e, 6);
	}
	return 0;
}
Пример #9
0
/// \file Entry point of tremppi_qualitative
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int tremppi_quantitative(int argc, char ** argv) 
{
	TremppiSystem::initiate("tremppi_quantitative", argc, argv);
	Logging logging;

	const vector<string> prefixes = { "K", "C", "R", "E", "B", "I" };
	RegInfos reg_infos;
	sqlite3pp::database db;
	vector<string> selections;
	vector<string> sels_name;
	DatabaseReader reader;
	try
	{
		DEBUG_LOG << "Reading data.";
		db = move(sqlite3pp::database((TremppiSystem::DATA_PATH / DATABASE_FILENAME).string().c_str()));
		selections = reader.getSelectionList();
		sels_name = reader.getSelectionNames();
		reg_infos = reader.readRegInfos(db);
	}
	catch (exception & e)
	{
		logging.exceptionMessage(e, 2);
	}

	// Create a report for each selection
	logging.newPhase("making report", selections.size());
	for (const size_t sel_no : cscope(selections))
	{
		Json::Value out;
		map<size_t, string> columns;
		vector<ComputedData> results;

		try
		{
			DEBUG_LOG << "Selection " + sels_name[sel_no];
			out = Report::createSetup(selections[sel_no], sels_name[sel_no]);
			for (const string & prefix : prefixes)
			{
				const auto new_columns = sqlite3pp::func::matchingColumns(PARAMETRIZATIONS_TABLE, regex{ prefix + "_.*" }, db);
				columns.insert(WHOLE(new_columns));
			}
			for (const pair<size_t, string> column : columns)
			{
				results.push_back(ComputedData{ column.second, 0, numeric_limits<double>::max(), -1 * numeric_limits<double>::max(), 0 });
			}
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 3);
		}

		const size_t row_count = sqlite3pp::func::rowCount(PARAMETRIZATIONS_TABLE, out["setup"]["select"].asString(), db);
		try
		{
			DEBUG_LOG << "Reading the values, computing the statistics.";
			logging.newPhase("Reading row", row_count);
			sqlite3pp::query group_qry = DatabaseReader::selectionFilter(columns, out["setup"]["select"].asString(), db);

			// Read the data
			for (auto row : group_qry)
			{
				for (int i = 0; i < group_qry.column_count(); i++) {
					if (row.column_type(i) == SQLITE_NULL)
					{
						throw runtime_error(string("A null valued entry in the column ") + group_qry.column_name(i));
					}
					double val;
					if (row.column_type(i) == SQLITE_INTEGER)
					{
						val = row.get<int>(i);
					}
					else if (row.column_type(i) == SQLITE_FLOAT)
					{
						val = row.get<double>(i);
					}
					if (val != 0)
					{
						results[i].count++;
					}
					results[i].min = min(results[i].min, val);
					results[i].max = max(results[i].max, val);
					results[i].mean += val;

				}
				logging.step();
			}
			// Compute mean
			for (ComputedData & result : results)
			{
				result.mean = result.mean / row_count;
			}
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 4);
		}

		try
		{
			DEBUG_LOG << "Writing results.";
			// For each graph create the graph data and add configuration details
			for (ComputedData & result : results)
			{
				Json::Value result_node;
				result_node["name"] = Report::reformName(reg_infos, result.name);
				result_node["count"] = static_cast<Json::Value::UInt>(result.count);
				result_node["min"] = result.min;
				result_node["max"] = result.max;
				result_node["mean"] = result.mean;
				out["records"].append(result_node);
			}

			FileManipulation::writeJSON(TremppiSystem::DATA_PATH / "quantitative" / (out["setup"]["s_name"].asString() + ".json"), out);
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 5);
		}
	}
	try
	{
		PythonFunctions::configure("quantitative");
	}
Пример #10
0
	/* Take the model and turn it into a steady state constraint. */
	void applyModel(const Model & model) {
		for (const size_t i : cscope(model.species)) {		
			Gecode::rel(*this, spec_vars[i] == convertRule(spec_vars, model, model.species[i]));
		}
	}