46 template <
typename GUM_SCALAR >
49 const std::string& extends,
51 bool delayInheritance) {
52 std::string real_name = __addPrefix(name);
53 if (__prm->__classMap.exists(real_name)
54 || __prm->__interfaceMap.exists(real_name)) {
61 if (implements != 0) {
62 for (
const auto& imp : *implements) {
63 impl.
insert(__retrieveInterface(imp));
67 if (extends !=
"") { mother = __retrieveClass(extends); }
69 if ((extends ==
"") && impl.
empty()) {
71 }
else if ((extends !=
"") && impl.
empty()) {
73 }
else if ((extends ==
"") && (!impl.
empty())) {
75 }
else if ((extends !=
"") && (!impl.
empty())) {
79 __prm->__classMap.insert(c->
name(), c);
80 __prm->__classes.insert(c);
84 template <
typename GUM_SCALAR >
86 std::string real_name = __addPrefix(name);
87 if (!(__prm->__classMap.exists(real_name))) {
88 std::stringstream msg;
89 msg <<
"'" << real_name <<
"' not found";
92 __stack.push_back(&(__prm->getClass(real_name)));
95 template <
typename GUM_SCALAR >
100 if (checkImplementations) { __checkInterfaceImplementation(c); }
105 template <
typename GUM_SCALAR >
111 for (
const auto& node : i->containerDag().nodes()) {
112 std::string name = i->get(node).name();
114 switch (i->get(node).elt_type()) {
117 if ((c->
get(name).elt_type()
119 || (c->
get(name).elt_type()
121 if (!c->
get(name).type().isSubTypeOf(i->get(name).type())) {
122 std::stringstream msg;
123 msg <<
"class " << c->
name()
124 <<
" does not respect interface ";
128 std::stringstream msg;
129 msg <<
"class " << c->
name() <<
" does not respect interface ";
137 if (c->
get(name).elt_type()
147 std::stringstream msg;
148 msg <<
"class " << c->
name()
149 <<
" does not respect interface ";
153 std::stringstream msg;
154 msg <<
"class " << c->
name() <<
" does not respect interface ";
168 "unexpected ClassElement<GUM_SCALAR> in interface ";
174 std::stringstream msg;
175 msg <<
"class " << c->
name() <<
" does not respect interface ";
185 template <
typename GUM_SCALAR >
188 const std::string& extends,
189 bool delayInheritance) {
190 std::string real_name = __addPrefix(name);
191 if (__prm->__classMap.exists(real_name)
192 || __prm->__interfaceMap.exists(real_name)) {
198 if (extends !=
"") { super = __retrieveInterface(extends); }
200 if (super !=
nullptr) {
206 __prm->__interfaceMap.insert(i->
name(), i);
207 __prm->__interfaces.insert(i);
208 __stack.push_back(i);
211 template <
typename GUM_SCALAR >
214 std::string real_name = __addPrefix(name);
215 if (!__prm->__interfaceMap.exists(real_name)) {
220 __stack.push_back(i);
223 template <
typename GUM_SCALAR >
231 attr->
cpf().variablesSequence();
235 if (vars.
exists(&(c->
get(node).type().variable()))) {
245 if (count != attr->
cpf().variablesSequence().size()) {
250 template <
typename GUM_SCALAR >
254 const std::string& name) {
261 "can not add a reference slot as a parent of an attribute");
268 "can not add a multiple slot chain to an attribute");
292 "found no ClassElement<GUM_SCALAR> with the given name ";
300 "Impossible to add a multiple reference slot as" 301 " direct parent of an PRMAttribute<GUM_SCALAR>.");
307 template <
typename GUM_SCALAR >
314 __addParent(c, a, name);
322 template <
typename GUM_SCALAR >
324 const std::vector< float >& array) {
329 if (a->
cpf().domainSize() != array.size())
332 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
333 a->
cpf().fillWith(array2);
336 template <
typename GUM_SCALAR >
338 const std::vector< GUM_SCALAR >& array) {
343 if (a->cpf().domainSize() != array.size()) {
347 a->cpf().fillWith(array);
350 template <
typename GUM_SCALAR >
352 const std::vector< float >& array) {
356 if (a->
cpf().domainSize() != array.size()) {
360 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
361 setRawCPFByColumns(array2);
364 template <
typename GUM_SCALAR >
366 const std::vector< GUM_SCALAR >& array) {
370 if (a->
cpf().domainSize() != array.size()) {
374 if (a->
cpf().nbrDim() == 1) {
375 setRawCPFByLines(array);
380 for (
auto idx = inst.variablesSequence().rbegin();
381 idx != inst.variablesSequence().rend();
387 auto idx = (std::size_t)0;
388 while ((!jnst.end()) && idx < array.size()) {
390 a->
cpf().set(inst, array[idx]);
397 template <
typename GUM_SCALAR >
399 const std::vector< std::string >& parents,
400 const std::vector< float >& values) {
404 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
408 if (values.size() != a->type().variable().domainSize()) {
412 std::vector< GUM_SCALAR > values2(values.begin(), values.end());
413 setCPFByRule(parents, values2);
416 template <
typename GUM_SCALAR >
418 const std::vector< std::string >& parents,
419 const std::vector< GUM_SCALAR >& values) {
423 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
427 if (values.size() != a->type().variable().domainSize()) {
440 for (
Idx i = 0; i < parents.size(); ++i) {
441 var = form->formulas().variablesSequence().atPos(1 + i);
443 if (parents[i] ==
"*") {
451 if (var->
label(j) == parents[i]) {
452 jnst.chgVal(*var, j);
459 std::string msg =
"could not find label ";
468 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
469 inst.
chgVal(form->type().variable(), i);
471 for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
481 template <
typename GUM_SCALAR >
483 const std::vector< std::string >& parents,
484 const std::vector< std::string >& values) {
488 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
492 if (values.size() != a->type().variable().domainSize()) {
505 for (
Idx i = 0; i < parents.size(); ++i) {
506 var = form->formulas().variablesSequence().atPos(1 + i);
508 if (parents[i] ==
"*") {
516 if (var->
label(j) == parents[i]) {
517 jnst.chgVal(*var, j);
524 std::string msg =
"could not find label ";
533 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
534 inst.
chgVal(form->type().variable(), i);
536 for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
537 form->formulas().set(inst, values[i]);
546 template <
typename GUM_SCALAR >
548 const std::string& name,
559 }
else if (type ==
"real") {
571 template <
typename GUM_SCALAR >
573 const std::string& name,
574 const std::string& agg_type,
575 const std::string& rv_type,
576 const std::vector< std::string >& params) {
583 *__retrieveType(rv_type));
589 switch (agg->agg_type()) {
593 if (params.size() != 1) {
596 agg->setLabel(params.front());
603 __stack.push_back(agg);
606 template <
typename GUM_SCALAR >
611 auto& agg = c->
get(name);
615 __stack.push_back(&agg);
618 template <
typename GUM_SCALAR >
622 const std::string& name) {
623 auto chains = std::vector< std::string >{name};
624 auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
625 __retrieveInputs(c, chains, inputs);
630 if (inputs.front()->type() != *(__retrieveType(
"boolean"))) {
644 while (label_idx < inputs.front()->type()->domainSize()) {
645 if (inputs.front()->type()->label(label_idx) == param) {
break; }
650 if (label_idx == inputs.front()->type()->domainSize()) {
675 template <
typename GUM_SCALAR >
681 template <
typename GUM_SCALAR >
683 const std::string& name,
684 const std::string& agg_type,
685 const std::vector< std::string >& chains,
686 const std::vector< std::string >& params,
692 if (chains.size() == 0) {
694 "a PRMAggregate<GUM_SCALAR> requires at least one parent");
698 std::vector< PRMClassElement< GUM_SCALAR >* > inputs;
703 bool hasSC = __retrieveInputs(c, chains, inputs);
708 if (inputs.size() > 1) {
709 for (
auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
710 if ((**(iter - 1)).type() != (**iter).type()) {
722 if (inputs.front()->type() != *(__retrieveType(
"boolean"))) {
725 if (params.size() != 0) {
732 inputs.front()->type());
739 if (params.size() != 1) {
745 while (label_idx < inputs.front()->type()->domainSize()) {
746 if (inputs.front()->type()->label(label_idx) == params.front()) {
753 if (label_idx == inputs.front()->type()->domainSize()) {
761 *(__retrieveType(
"boolean")),
772 if (params.size() != 0) {
776 auto output_type = __retrieveType(type);
786 if (params.size() != 1) {
792 while (label_idx < inputs.front()->type()->domainSize()) {
793 if (inputs.front()->type()->label(label_idx) == params.front()) {
800 if (label_idx == inputs.front()->type()->domainSize()) {
804 auto output_type = __retrieveType(type);
821 std::string safe_name = agg->
safeName();
844 for (
const auto& elt : inputs) {
845 c->
addArc(elt->safeName(), safe_name);
849 template <
typename GUM_SCALAR >
851 const std::string& name,
857 slotType = __retrieveClass(type);
860 slotType = __retrieveInterface(type);
874 template <
typename GUM_SCALAR >
876 const std::string& name,
886 for (
Size i = 0; i < size; ++i) {
887 std::stringstream elt_name;
888 elt_name << name <<
"[" << i <<
"]";
890 model->
add(name, inst);
901 template <
typename GUM_SCALAR >
903 const std::string& r_i) {
909 model->
add(l_i, model->
get(r_i));
918 template <
typename GUM_SCALAR >
920 const std::string& l_i,
const std::string& l_ref,
const std::string& r_i) {
923 std::vector< PRMInstance< GUM_SCALAR >* > lefts;
924 std::vector< PRMInstance< GUM_SCALAR >* > rights;
926 if (model->isInstance(l_i)) {
927 lefts.push_back(&(model->get(l_i)));
928 }
else if (model->isArray(l_i)) {
929 for (
const auto& elt : model->getArray(l_i))
930 lefts.push_back(elt);
935 if (model->isInstance(r_i)) {
936 rights.push_back(&(model->get(r_i)));
937 }
else if (model->isArray(r_i)) {
938 for (
const auto& elt : model->getArray(r_i))
939 rights.push_back(elt);
944 for (
const auto l : lefts) {
945 for (
const auto r : rights) {
946 auto& elt = l->type().get(l_ref);
948 l->add(elt.id(), *r);
957 template <
typename GUM_SCALAR >
960 std::vector< std::string > v;
966 for (
size_t i = 0; i < v.size(); ++i) {
968 switch (current->
get(v[i]).elt_type()) {
971 current->
get(v[i])));
980 if (i == v.size() - 1) {
991 }
catch (
NotFound&) {
return nullptr; }
994 GUM_ASSERT(v.size() == elts.
size());
1001 template <
typename GUM_SCALAR >
1004 const std::vector< std::string >& chains,
1006 bool retVal =
false;
1008 for (
size_t i = 0; i < chains.size(); ++i) {
1010 inputs.push_back(&(c->
get(chains[i])));
1014 inputs.push_back(__buildSlotChain(c, chains[i]));
1017 if (inputs.back()) {
1018 c->
add(inputs.back());
1025 PRMType* t = __retrieveCommonType(inputs);
1027 std::vector< std::pair< PRMClassElement< GUM_SCALAR >*,
1031 for (
const auto& elt : inputs) {
1032 if ((*elt).type() != (*t)) {
1036 std::stringstream name;
1038 for (
Size idx = 0; idx < sc->
chain().size() - 1; ++idx) {
1039 name << sc->
chain().atPos(idx)->name() <<
".";
1042 name <<
".(" << t->
name() <<
")" << sc->
lastElt().name();
1045 toAdd.push_back(std::make_pair(elt, &(c->
get(name.str()))));
1048 std::make_pair(elt, __buildSlotChain(c, name.str())));
1051 std::stringstream name;
1052 name <<
"(" << t->
name() <<
")" << elt->name();
1053 toAdd.push_back(std::make_pair(elt, &(c->
get(name.str()))));
1061 template <
typename GUM_SCALAR >
1064 const PRMType* current =
nullptr;
1068 for (
const auto& elt : elts) {
1070 current = &((*elt).type());
1072 while (current != 0) {
1075 ++(counters[current->
name()]);
1081 if (current->isSubType()) {
1082 current = &(current->superType());
1089 "found a ClassElement<GUM_SCALAR> without a type");
1098 int current_depth = 0;
1100 for (
const auto& elt : counters) {
1101 if ((elt.second) == elts.size()) {
1102 current_depth = __typeDepth(__retrieveType(elt.first));
1104 if (current_depth > max_depth) {
1105 max_depth = current_depth;
1106 current = __retrieveType(elt.first);
1111 if (current) {
return const_cast< PRMType*
>(current); }
1116 template <
typename GUM_SCALAR >
1118 const std::string& name,
1119 const std::vector< std::string >& chains,
1120 const std::vector< float >& numbers,
1122 const std::vector< std::string >& labels) {
1130 std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1132 for (
const auto& elt : chains)
1133 parents.push_back(&(c->
get(elt)));
1135 PRMType* common_type = __retrieveCommonType(parents);
1137 for (
size_t idx = 0; idx < parents.size(); ++idx) {
1138 if (parents[idx]->type() != (*common_type)) {
1142 std::string safe_name = parent->
cast(*common_type);
1144 if (!c->
exists(safe_name)) {
1146 parents[idx] = __buildSlotChain(c, safe_name);
1147 c->
add(parents[idx]);
1152 parents[idx] = &(c->
get(safe_name));
1157 if (numbers.size() == 1) {
1161 name, retrieveType(
"boolean"), impl);
1163 }
else if (numbers.size() == parents.size()) {
1168 name, retrieveType(
"boolean"), noisy);
1170 for (
size_t idx = 0; idx < numbers.size(); ++idx) {
1171 noisy->
causalWeight(parents[idx]->type().variable(), numbers[idx]);
1179 if (!labels.empty()) {
1181 "labels definitions not handle for noisy-or");
1185 template <
typename GUM_SCALAR >
1189 std::string full_name;
1192 if (__prm->__typeMap.exists(name)) {
1193 type = __prm->__typeMap[name];
1198 std::string prefixed = __addPrefix(name);
1199 if (__prm->__typeMap.exists(prefixed)) {
1201 type = __prm->__typeMap[prefixed];
1202 full_name = prefixed;
1203 }
else if (full_name != prefixed) {
1205 "Type name '" << name <<
"' is ambiguous: specify full name.");
1210 std::string relatif_ns = currentPackage();
1211 size_t last_dot = relatif_ns.find_last_of(
'.');
1212 if (last_dot != std::string::npos) {
1213 relatif_ns = relatif_ns.substr(0, last_dot) +
'.' + name;
1214 if (__prm->__typeMap.exists(relatif_ns)) {
1216 type = __prm->__typeMap[relatif_ns];
1217 full_name = relatif_ns;
1218 }
else if (full_name != relatif_ns) {
1220 "Type name '" << name
1221 <<
"' is ambiguous: specify full name.");
1228 if (!__namespaces.empty()) {
1229 auto ns_list = __namespaces.back();
1230 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1231 std::string ns = (*ns_list)[i];
1232 std::string ns_name = ns +
"." + name;
1233 if (__prm->__typeMap.exists(ns_name)) {
1235 type = __prm->__typeMap[ns_name];
1236 full_name = ns_name;
1237 }
else if (full_name != ns_name) {
1239 "Type name '" << name
1240 <<
"' is ambiguous: specify full name.");
1253 template <
typename GUM_SCALAR >
1257 std::string full_name;
1260 if (__prm->__classMap.exists(name)) {
1261 a_class = __prm->__classMap[name];
1266 std::string prefixed = __addPrefix(name);
1267 if (__prm->__classMap.exists(prefixed)) {
1268 if (a_class ==
nullptr) {
1269 a_class = __prm->__classMap[prefixed];
1270 full_name = prefixed;
1271 }
else if (full_name != prefixed) {
1273 "Class name '" << name
1274 <<
"' is ambiguous: specify full name.");
1279 if (!__namespaces.empty()) {
1280 auto ns_list = __namespaces.back();
1281 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1282 std::string ns = (*ns_list)[i];
1283 std::string ns_name = ns +
"." + name;
1284 if (__prm->__classMap.exists(ns_name)) {
1286 a_class = __prm->__classMap[ns_name];
1287 full_name = ns_name;
1288 }
else if (full_name != ns_name) {
1290 "Class name '" << name
1291 <<
"' is ambiguous: specify full name.");
1304 template <
typename GUM_SCALAR >
1306 const std::string& name)
const {
1308 std::string full_name;
1311 if (__prm->__interfaceMap.exists(name)) {
1312 interface = __prm->__interfaceMap[name];
1317 std::string prefixed = __addPrefix(name);
1318 if (__prm->__interfaceMap.exists(prefixed)) {
1319 if (interface ==
nullptr) {
1320 interface = __prm->__interfaceMap[prefixed];
1321 full_name = prefixed;
1322 }
else if (full_name != prefixed) {
1324 "Interface name '" << name
1325 <<
"' is ambiguous: specify full name.");
1330 if (!__namespaces.empty()) {
1331 auto ns_list = __namespaces.back();
1333 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1334 std::string ns = (*ns_list)[i];
1335 std::string ns_name = ns +
"." + name;
1337 if (__prm->__interfaceMap.exists(ns_name)) {
1338 if (interface ==
nullptr) {
1339 interface = __prm->__interfaceMap[ns_name];
1340 full_name = ns_name;
1341 }
else if (full_name != ns_name) {
1344 << name <<
"' is ambiguous: specify full name.");
1350 if (interface ==
nullptr) {
1352 "Interface '" << name <<
"' not found, check imports.");
1358 template <
typename GUM_SCALAR >
1364 template <
typename GUM_SCALAR >
1370 template <
typename GUM_SCALAR >
1380 template <
typename GUM_SCALAR >
1385 template <
typename GUM_SCALAR >
1389 return __stack.back()->obj_type();
1392 template <
typename GUM_SCALAR >
1399 template <
typename GUM_SCALAR >
1406 template <
typename GUM_SCALAR >
1417 template <
typename GUM_SCALAR >
1422 template <
typename GUM_SCALAR >
1425 std::string super) {
1427 if (
__prm->__typeMap.exists(real_name)) {
1436 t->__label_map =
new std::vector< Idx >();
1441 template <
typename GUM_SCALAR >
1443 std::string extends) {
1444 if (extends ==
"") {
1451 "the current type's variable is not a LabelizedVariable.");
1452 }
else if (t->__superType) {
1468 "the current type's variable is not a LabelizedVariable.");
1469 }
else if (!t->__superType) {
1475 for (
Idx i = 0; i < t->__superType->__var->
domainSize(); ++i) {
1476 if (t->__superType->__var->
label(i) == extends) {
1483 t->__label_map->push_back(i);
1494 template <
typename GUM_SCALAR >
1499 if (!t->__isValid()) {
1503 "current type is not a valid discrete type");
1508 __prm->__types.insert(t);
1512 template <
typename GUM_SCALAR >
1516 if (
__prm->__typeMap.exists(real_name)) {
1524 template <
typename GUM_SCALAR >
1533 "the current type's variable is not a LabelizedVariable.");
1543 template <
typename GUM_SCALAR >
1550 "current type is not a valid discrete type");
1555 __prm->__types.insert(t);
1559 template <
typename GUM_SCALAR >
1564 if (
__prm->__typeMap.exists(real_name)) {
1565 std::stringstream msg;
1566 msg <<
"\"" << real_name <<
"' is already used.";
1573 if (t->variable().domainSize() < 2) {
1575 "current type is not a valid discrete type");
1578 __prm->__typeMap.insert(t->name(), t);
1579 __prm->__types.insert(t);
1582 template <
typename GUM_SCALAR >
1588 template <
typename GUM_SCALAR >
1590 const std::string& name) {
1596 template <
typename GUM_SCALAR >
1598 const std::string& name,
1613 std::string dot =
".";
1620 if (a !=
nullptr && (!c->
exists(a->
id()))) {
delete a; }
1626 template <
typename GUM_SCALAR >
1631 auto& a = c->
get(name);
1638 template <
typename GUM_SCALAR >
1644 template <
typename GUM_SCALAR >
1646 if (
__prm->__systemMap.exists(name)) {
1652 __prm->__systemMap.insert(model->
name(), model);
1653 __prm->__systems.insert(model);
1656 template <
typename GUM_SCALAR >
1666 template <
typename GUM_SCALAR >
1668 const std::string& name) {
1672 if (c->parameters().size() > 0) {
1681 template <
typename GUM_SCALAR >
1683 const std::string& type,
1684 const std::string& name,
1688 if (c->parameters().empty()) {
1689 if (params.
empty()) {
1693 "Class " + type +
" does not have parameters");
1697 auto my_params = params;
1699 for (
const auto& p : c->parameters()) {
1700 if (!my_params.exists(p->name())) {
1701 my_params.
insert(p->name(), p->value());
1706 std::stringstream sBuff;
1707 sBuff << c->name() <<
"<";
1709 for (
const auto& p : my_params) {
1710 sBuff << p.first <<
"=" << p.second <<
",";
1714 std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) +
">";
1724 for (
auto p : my_params) {
1747 template <
typename GUM_SCALAR >
1750 const std::string& name) {
1759 if (i) {
delete i; }
1764 template <
typename GUM_SCALAR >
1769 full_name.append(
".");
1770 full_name.append(str);
1777 template <
typename GUM_SCALAR >
1795 template <
typename GUM_SCALAR >
1813 template <
typename GUM_SCALAR >
1836 template <
typename GUM_SCALAR >
1841 while (current->isSubType()) {
1843 current = &(current->superType());
1849 template <
typename GUM_SCALAR >
1855 template <
typename GUM_SCALAR >
1873 template <
typename GUM_SCALAR >
1875 if (name.size() == 0) {
1884 template <
typename GUM_SCALAR >
1887 const std::string& r_i) {
1888 size_t pos = l_i.find_last_of(
'.');
1890 if (pos != std::string::npos) {
1891 std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1898 template <
typename GUM_SCALAR >
1904 template <
typename GUM_SCALAR >
1910 template <
typename GUM_SCALAR >
1917 template <
typename GUM_SCALAR >
1919 const std::string& type)
const {
1937 template <
typename GUM_SCALAR >
1939 const std::string& name)
const {
1942 return (system && system->
isArray(name));
1945 template <
typename GUM_SCALAR >
1947 const std::vector< std::string >& array) {
1953 if (a->formulas().domainSize() != array.size()) {
1957 if (a->formulas().nbrDim() == 1) {
1963 for (
auto idx = inst.variablesSequence().rbegin();
1964 idx != inst.variablesSequence().rend();
1970 auto idx = (std::size_t)0;
1971 while ((!jnst.end()) && idx < array.size()) {
1973 a->formulas().set(inst, array[idx]);
1983 template <
typename GUM_SCALAR >
1985 const std::vector< std::string >& array) {
1991 if (a->formulas().domainSize() != array.size()) {
1995 a->formulas().populate(array);
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::add(PRMClassElement<GUM_SCALAR>*).
const Set< PRMInterface< GUM_SCALAR > *> & implements() const
Returns the Set of PRMInterface<GUM_SCALAR> implemented by this Class<GUM_SCALAR>.
PRMParameter is a member of a Class in a PRM.
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
virtual void endInterface() override
Tells the factory that we finished an interface declaration.
virtual void pushPackage(const std::string &name) override
Define the current package.
virtual void addAggregator(const std::string &name, const std::string &agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string type="") override
Add an aggregator in the current declared class.
virtual void addRangeType(const std::string &name, long minVal, long maxVal) override
Add a range variable type declaration.
bool empty() const noexcept
Indicates whether the set is the empty set.
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate...
void add(NodeId id, PRMInstance< GUM_SCALAR > &instance)
Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node...
void endAggregator()
Finishes an aggregate declaration.
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~PRMFactory()
Destructor.
virtual void addNoisyOrCompound(const std::string &name, const std::vector< std::string > &chains, const std::vector< float > &numbers, float leak, const std::vector< std::string > &label) override
Add a compound noisy-or as an PRMAttribute<GUM_SCALAR> to the current Class<GUM_SCALAR>.
const std::string & name() const
Returns the name of this object.
virtual std::string popPackage() override
Pop the current package from the package stack.
Size size() const noexcept
Returns the size of the sequence.
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
virtual void setRawCPFByFloatColumns(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
virtual PRMType & type()=0
See gum::PRMClassElement::type().
virtual void addArray(const std::string &type, const std::string &name, Size size) override
Creates an array with the given number of instances of the given type.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
virtual void setCPFByFloatRule(const std::vector< std::string > &labels, const std::vector< float > &values) override
Fills the CPF using a rule.
The generic class for storing (ordered) sequences of objects.
Class for discretized random variable.
virtual prm_type obj_type() const =0
Returns the type of this object.
PRMType * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local na...
virtual void continueClass(const std::string &c) override
Continue the declaration of a class.
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
virtual void continueInterface(const std::string &name) override
Continue the declaration of an interface.
Abstract class representing an element of PRM class.
virtual void addImport(const std::string &name) override
Add an import for namespace lookup.
virtual void startDiscretizedType(const std::string &name) override
Start a discretized type declaration.
PRMClass< GUM_SCALAR > & retrieveClass(const std::string &name)
Returns a reference over a Class<GUM_SCALAR> given its name.
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
virtual void startInterface(const std::string &i, const std::string &ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
virtual void addReferenceSlot(const std::string &type, const std::string &name, bool isArray) override
Tells the factory that we started declaring a slot.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
virtual PRMClassElement< GUM_SCALAR > & get(const std::string &name)=0
Getter on a member of this PRMClassElementContainer.
PRMType & retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
Base class for discrete random variable.
PRMType & retrieveType(const std::string &name)
Returns a reference over a PRMType given its name.
virtual bool exists(const std::string &name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
void __addInstance(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
void setLabel(Idx idx)
Set the aggregator's label.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject)...
void continueAggregator(const std::string &name)
Conitnues an aggregator declaration.
virtual void incArray(const std::string &l_i, const std::string &r_i) override
Add an instance to an array.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
virtual void setRawCPFByFloatLines(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
virtual std::string currentPackage() const override
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
virtual Size domainSize() const =0
PRMType * __retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
prm_type
Enumeration of the different types of objects handled by a PRM.
virtual PRMObject::prm_type currentType() const override
bool isInstance(const std::string &name) const
Returns true if an PRMInstance with the given name exists.
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
Factory which builds a PRM<GUM_SCALAR>.
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
std::string to_string(const Formula &f)
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
DiscretizedVariable & addTick(const T_TICKS &aTick)
add a tick.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
AggregateType agg_type() const
Returns the aggregate of *this.
virtual const Potential< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
<agrum/PRM/elements/funcAttribute.h>
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
virtual void addArc(const std::string &tail, const std::string &head)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::addArc().
PRMSlotChain< GUM_SCALAR > * __buildSlotChain(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
void __addParent(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
bool exists(const Key &k) const
Check the existence of k in the sequence.
Base class for all aGrUM's exceptions.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
virtual PRMObject * getCurrent() override
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::overload(PRMClassElement<GUM_SCALAR>*).
std::vector< std::string > __packages
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
PRMFactory()
Default constructor.
This is a decoration of the DiscreteVariable class.
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
virtual PRMObject * closeCurrent() override
Close current object being built.
Defines a discrete random variable over an integer interval.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> to this PRMClassElementContainer.
Abstract base class for any element defined in a PRM.
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> which overload an inherited PRMClassElement<GUM_SCALAR>.
void __checkInterfaceImplementation(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
Class for assigning/browsing values to tuples of discrete variables.
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual void setOutputNode(const PRMClassElement< GUM_SCALAR > &elt, bool b)
Set the output flag value of id at b.
bool hasLabel() const
Returns true if the label is defined.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
std::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
virtual void startDiscreteType(const std::string &name, std::string super="") override
Start a discrete subtype declaration.
PRMClass< GUM_SCALAR > * __retrieveClass(const std::string &name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...
virtual void endDiscretizedType() override
End the current discretized type declaration.
<agrum/PRM/classElementContainer.h>
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
NodeId id() const
Returns the NodeId of this element in it's class DAG.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
bool isArray(const std::string &name) const
Returns true if an array with the given name exists.
void decomposePath(const std::string &path, std::vector< std::string > &v)
Decompose a string in a vector of strings using "." as separators.
virtual void endDiscreteType() override
End the current discrete type declaration.
virtual void continueAttribute(const std::string &name) override
Continues the declaration of an attribute.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size Idx
Type for indexes.
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
std::vector< List< std::string > *> __namespaces
Set of all declared namespaces.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
int __typeDepth(const PRMType *t)
Returns the inheritance depth of a PRMType.
virtual bool isClassOrInterface(const std::string &type) const override
virtual void addLabel(const std::string &l, std::string ext="") override
Add a label to the current discrete type.
PRMAttribute is a member of a Class in a PRM.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
virtual void addArc(const std::string &tail, const std::string &head)=0
Add an arc between two PRMClassElement<GUM_SCALAR>.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
const std::string & name() const
returns the name of the variable
virtual void endSystem() override
Tells the factory that we finished declaring a model.
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
bool empty() const noexcept
Indicates whether the hash table is empty.
void addArray(const std::string &array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn't exists it is created.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
<agrum/PRM/elements/scalarAttribute.h>
Idx label() const
Returns the label's index on which this aggregate applies.
PRMInterface< GUM_SCALAR > * __retrieveInterface(const std::string &name) const
Returns a pointer on an interface given it's name. Used when building models, meaning that the interf...
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
virtual bool isArrayInCurrentSystem(const std::string &name) const override
void insert(const Key &k)
Inserts a new element into the set.
const Key & back() const
Returns the last element of the sequence.
void startAggregator(const std::string &name, const std::string &agg_type, const std::string &rv_type, const std::vector< std::string > ¶ms)
Start an aggregator declaration.
virtual void addParent(const std::string &name) override
Tells the factory that we add a parent to the current declared attribute.
#define GUM_ERROR(type, msg)
virtual void addTick(double tick) override
Add a tick to the current discretized type.
Sequence< PRMClassElement< GUM_SCALAR > *> & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
non-template interface-like parent for every PRM Factory
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __retrieveInputs(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
void insert(const Key &k)
Insert an element at the end of the sequence.