14 , index(
std::numeric_limits<size_t>::max())
15 , id(attribute->id.value.value)
16 , expression(getExpression(attribute->name.value.value,attributeRegistry))
17 , name(getName(attribute->name.value.value))
20 attributeRegistry.add(
this);
22 throw std::runtime_error(
"Attribute: timestamp must be first status attribute");
25 throw std::runtime_error(
"Attribute: instance must be first data attribute");
33 type = ValueType::BOOLEAN;
36 type = ValueType::INTEGER;
39 type = ValueType::DECIMAL;
42 type = ValueType::STRING;
45 type = ValueType::COLLECTION;
48 if ( attribute->
weight.has_value() ) {
49 if ( attribute->objective.has_value() && attribute->objective->get().value.value ==
"maximize" ) {
50 weight = (double)attribute->weight->get().value;
52 else if ( attribute->
objective.has_value() && attribute->
objective->get().value.value ==
"minimize" ) {
53 weight = -(double)attribute->weight->get().value;
56 throw std::runtime_error(
"Attribute: illegal objective of attribute '" + id +
"'");
60 if ( attribute->objective.has_value() && attribute->objective->get().value.value !=
"none" ) {
61 throw std::runtime_error(
"Attribute: required objective weight missing for attribute '" +
id +
"'");
69std::unique_ptr<const Expression> Attribute::getExpression(std::string& input,
AttributeRegistry& attributeRegistry) {
70 if ( !input.contains(
":=") ) {
76 assert( root.operands.size() == 1 );
77 assert( root.type == LIMEX::Type::group );
78 auto& node = std::get< LIMEX::Node<double> >(root.operands[0]);
79 if ( node.type != LIMEX::Type::assign ) {
80 throw std::runtime_error(
"Attribute: illegal initialization '" + input +
"' for attribute '" +
id +
"'");
85std::string Attribute::getName(std::string& input) {
87 assert(
expression->compiled.getTarget().has_value() );
88 return expression->compiled.getTarget().value();
std::unique_ptr< const Expression > expression
size_t index
Index of attribute (is automatically set by attribute registry).
Attribute(XML::bpmnos::tAttribute *attribute, Attribute::Category category, AttributeRegistry &attributeRegistry)
Class representing a mathematical expression.
std::optional< const Attribute * > target
Attribute & type
Attribute value can be expected to be of type 'std::string'.
std::optional< std::reference_wrapper< Attribute > > weight
Attribute value can be expected to be of type 'double'.
std::optional< std::reference_wrapper< Attribute > > objective
Attribute value can be expected to be of type 'std::string'.
const std::string Instance
const std::string Timestamp
std::string encodeQuotedStrings(std::string text)
std::string encodeCollection(std::string text)
Function to replace a collection that is not preceded by an alphanumeric or underscore.
static constexpr size_t Instance
static constexpr size_t Timestamp