示例#1
0
 def addScenarioParameters(self,
                           replication=None,
                           seed=None,
                           baseTimeUnit=None,
                           baseCurrencyUnit=None,
                           showResultRequestColumn=None,
                           expressionLanguage=None,
                           baseResultFrequency=None,
                           baseResultFrequencyCumul=None,
                           traceOutput=None,
                           traceFormat=None):
     self.ScenarioParameters = sp.ScenarioParameters(
         replication, seed, baseTimeUnit, baseCurrencyUnit,
         showResultRequestColumn, expressionLanguage, baseResultFrequency,
         baseResultFrequencyCumul, traceOutput, traceFormat, self.verbosity)
     self.scenarioParametersAttrib = self.ScenarioParameters.filterScenarioParametersAttributes(
     )
     self.root.insert(
         0,
         etree.Element(utility.BPSIM + "ScenarioParameters",
                       attrib=self.scenarioParametersAttrib))
     self.scenarioParametersPointer = self.root.find(utility.BPSIM +
                                                     "ScenarioParameters")
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Scenario parameters added" +
               str(self.scenarioParametersAttrib))
 def addTriggerCount(self, value=None, validFor=None):
     self.checkControlParametersTag()
     if type(value) == int:
         self.typeValueTC = "NumericParameter"
         self.triggerCountAttrib = {
             "value": str(value),
             "validFor": validFor
         }
         self.triggerCountAttrib = utility.filterNoneAttributes(
             self.triggerCountAttrib)
         if self.triggerCountPointer is None:
             self.triggerCountPointer = etree.SubElement(
                 self.controlPointer, utility.BPSIM + "TriggerCount")
         new_parameter = etree.SubElement(self.triggerCountPointer,
                                          utility.BPSIM + self.typeValueTC,
                                          attrib=self.triggerCountAttrib)
         utility.write_on_file(self.write, self.tree)
         utility.checkCalendar(self.scenario.getCalendars(), validFor,
                               self.verbosity)
         if self.verbosity == 0:
             print("INFO: TriggerCount added " + self.typeValueTC + " ",
                   self.triggerCountAttrib)
     else:
         raise ValueError(
             "ERROR: Type of TriggerCount is not correct, must be NumericParameter"
         )
 def addCondition(self, value=None, expression=None):
     self.checkControlParametersTag()
     if (value == None and expression == None) or (value != None
                                                   and expression != None):
         raise ValueError(
             "ERROR: Condition requires BooleanParameter or ExpressionParameter"
         )
     else:
         if self.conditionPointer is None:
             self.conditionPointer = etree.SubElement(
                 self.controlPointer, utility.BPSIM + "Condition")
         if value is not None:
             if super().checkBooleanParameter(value):
                 self.typeValueC = "BooleanParameter"
                 condition = etree.SubElement(self.conditionPointer,
                                              utility.BPSIM +
                                              self.typeValueC,
                                              attrib={"value": str(value)})
                 if self.verbosity == 0:
                     print("INFO: Condition added BooleanParameter",
                           {"value": value})
             else:
                 raise ValueError("ERROR: value must be BooleanParameter")
         if expression is not None:
             self.typeValueC = "ExpressionParameter"
             super().addExpressionParameter(expression,
                                            self.conditionPointer,
                                            self.typeValueC)
             if self.verbosity == 0:
                 print("INFO: Condition added ExpressionParameter",
                       {"expression": expression})
     utility.write_on_file(self.write, self.tree)
示例#4
0
    def addScenario(self,
                    name=None,
                    id=None,
                    author=None,
                    description=None,
                    created=None,
                    modified=None,
                    version=None,
                    vendor=None,
                    inherits=None):
        scenario = Scenario.Scenario(name, id, author, description, created,
                                     modified, version, vendor, inherits,
                                     self.verbosity)
        attrib = scenario.filterScenarioAttributes()
        if bool(attrib):
            self.scenarioPointer = etree.SubElement(self.bpsimData,
                                                    utility.BPSIM + "Scenario",
                                                    attrib=attrib)
            scenario.setPointer(self.scenarioPointer, self.root, self.tree)
            if self.vendorNamespace is not None:
                scenario.setVendorNamespace(self.vendorNamespace)
            self.scenarioList.append(scenario)
            utility.write_on_file(self.root, self.tree)
        else:
            raise ValueError('ERROR: Empty Scenario')

        self.createScenario = True
        if self.verbosity == 0:
            print("INFO: Added Scenario " + str(attrib))
        return scenario
示例#5
0
	def setProperty(self, name, type=None, value=None, enum_list=None,timeUnit = None, nameDistribution = None, shape = None, scale = None, probability = None, trials = None, mean = None, k = None, standardDeviation = None, mode = None, min = None, max = None, discrete = None, points = None, expression = None):
		if self.pointer is None:
			raise ValueError("ERROR: Property not exist")
		if value is None and nameDistribution is None and enum_list is None and expression is None:
			raise ValueError('ERROR: to set Property insert value or enum_list or nameDistribution or expression')
		self.pointer.attrib['name'] = name
		if type is not None:
			self.pointer.attrib['type'] = type
		if nameDistribution is None and expression is None:
			if self.typeValue == self.nameDistribution:
				self.propertyAttrib = {}
			super().setParameterWithEnumList(self.typeValue, self.pointer, self.propertyAttrib,value,enum_list, timeUnit, None)
		newProperty=self.pointer.find("./" + utility.BPSIM + self.typeValue)
		self.pointer.remove(newProperty)
		if value is None and nameDistribution is not None and enum_list is None and expression is None:
			super().checkNameDistribution(nameDistribution)
			newPropertyAttrib= super().filterDistributionAttributes(timeUnit,nameDistribution, shape, scale, probability, trials, mean, k, standardDeviation, mode, min, max, discrete, points, validFor)
			if nameDistribution == 'UserDistribution':
				super().createUserDistributionDataPoint(points, self.pointer, discrete, timeUnit)
			else:
				new_parameter= etree.SubElement(self.pointer, utility.BPSIM + nameDistribution, attrib = newPropertyAttrib)
		elif value is None and nameDistribution is None and enum_list is None and expression is  not None:
			if super().checkStringParameter(expression):
				self.typeValue = "ExpressionParameter"
				newProperty= etree.SubElement(self.pointer, utility.BPSIM + self.typeValue, attrib = {"value": expression})
			else:
				raise ValueError("ERROR: ExpressionParameter must be a String")
		else:
			raise ValueError('ERROR: to set Property insert value or enum_list or nameDistribution or expression')
		utility.write_on_file(self.write, self.tree)
		if self.verbosity==0:
			print("INFO: Property updated")
示例#6
0
 def remove(self):
     parent = self.root.getparent()
     for child in parent:
         if child == self.root:
             parent.remove(child)
     if self.verbosity == 0:
         print("INFO: Scenario (", self.name, ") removed")
     utility.write_on_file(self.write, self.tree)
示例#7
0
 def addXmlns(self, name, value):
     utility.checkNameSpace(name, value)
     self.root.set('{xmlns}' + name, value)
     self.registerNamespace(name, value)
     utility.write_on_file(self.root, self.tree)
     self.vendorNamespace = value
     for scenario in self.scenarioList:
         scenario.setVendorNamespace(value)
         scenario.setVendorNameSpaceToElementParameters(value)
 def remove(self):
     parent = self.elementRefPointer.getparent()
     for child in parent:
         if child == self.elementRefPointer:
             parent.remove(child)
     if self.verbosity == 0:
         print("INFO: ElementParameters ", {'elementRef': self.elementRef},
               " removed")
     utility.write_on_file(self.write, self.tree)
示例#9
0
	def setSelection(self, value = None, expression = None, result_request = None):
		if self.selectionPointer is None:
			raise ValueError("ERROR: Selection not exixts")
		new_parameter = self.selectionPointer.findall("./" + utility.BPSIM + self.typeValueS)
		self.selectionPointer.remove(new_parameter[-1])
		self.addSelectionParameter(value, expression, result_request)
		utility.write_on_file(self.write, self.tree)
		if self.verbosity==0:
			print("INFO: Selection updated ")
示例#10
0
	def addSelection(self, value= None, expression=None, result_request=None):
		self.checkResourceParametersTag()
		self.addSelectionParameter(value, expression, result_request)
		utility.write_on_file(self.write, self.tree)
		if result_request is None:
			if self.verbosity==0:
				print("INFO: Selection added " + self.typeValueS + " ", self.selectionAttrib)
		else:
			if self.verbosity==0:
				print("INFO: Selection added " + self.typeValueS + " ", result_request)
示例#11
0
	def addQueueLength(self, resultRequest): 
		self.checkPropertyParametersTag()
		if self.queueLengthPointer is None:
			self.queueLengthPointer=etree.SubElement(self.propertyPointer, utility.BPSIM + "QueueLength")
		result = etree.SubElement(self.queueLengthPointer, utility.BPSIM + "ResultRequest")
		utility.checkResultRequest(resultRequest)
		result.text=resultRequest
		utility.write_on_file(self.write, self.tree)
		if self.verbosity==0:
			print("INFO: QueueLength added ResultRequest: ", resultRequest)
 def addVendorExtension(self, name, tree_list):
     if self.vendorNamespace not in self.write.attrib.values():
         raise ValueError('ERROR: add VendorExtension after adding xmlns')
     utility.addVendorExtension(name, tree_list, self.elementRefPointer,
                                self.vendorNamespace)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: ElementParameters VendorExtension added " + name)
         for tree in tree_list:
             etree.dump(tree)
示例#13
0
 def setInherits(self, inherits):
     if inherits is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.inherits = inherits
     self.root.set('inherits', inherits)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Inherits of Scenario updated ")
示例#14
0
 def removeScenarioAttribute(self, key):
     if key not in self.attributes:
         print("WARNING: Attribute not found")
     else:
         self.attributes.pop(key)
         if self.verbosity == 0:
             print('INFO: attribute deleted', key)
     if key in self.root.attrib:
         del self.root.attrib[key]
     utility.write_on_file(self.write, self.tree)
示例#15
0
 def setModified(self, modified):
     if modified is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.modified = modified
     self.root.set('modified', modified)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Modified of Scenario updated ")
示例#16
0
 def setVendor(self, vendor):
     if vendor is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.vendor = vendor
     self.root.set('vendor', vendor)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Vendor of Scenario updated ")
示例#17
0
 def setId(self, id):
     if id is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.id = id
     self.root.set('id', id)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Id of Scenario updated ")
示例#18
0
 def setName(self, name):
     if name is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.name = name
     self.root.set('name', name)
     utility.write_on_file(self.root, self.tree)
     if self.verbosity == 0:
         print("INFO: Name of Scenario updated ")
示例#19
0
 def setDescription(self, description):
     if description is None:
         raise ValueError(
             "ERROR: Invalid value. Use remove method to make the attribute None"
         )
     self.description = description
     self.root.set('description', description)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Description of Scenario updated")
示例#20
0
 def setUnitCost(self, value=None, validFor=None, resultRequest=None):
     if self.unitCostPointer is None:
         raise ValueError("ERROR: UnitCost not exists")
     new_parameter = self.unitCostPointer.findall("./" + utility.BPSIM +
                                                  self.typeValueUC)
     self.unitCostPointer.remove(new_parameter[-1])
     self.typeValueUC, self.unitCostPointer, self.unitCostAttributes = self.addCostParameter(
         value, validFor, resultRequest, self.unitCostPointer, 'UnitCost')
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: UnitCost updated")
 def addInterTriggerTimerResultRequest(self, result_request):
     self.checkControlParametersTag()
     if self.triggerTimePointer is None:
         self.triggerTimePointer = etree.SubElement(
             self.controlPointer, utility.BPSIM + "InterTriggerTimer")
     request = etree.SubElement(self.triggerTimePointer,
                                utility.BPSIM + "ResultRequest")
     request.text = result_request
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: ResultRequest added ", result_request)
示例#22
0
 def addVendorExtension(self, name, tree_list):
     if self.vendorNamespace not in self.write.attrib.values():
         raise ValueError(
             'ERROR: To insert VendorExtension first add xmlns')
     utility.addVendorExtension(name, tree_list, self.root,
                                self.vendorNamespace)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Scenario VendorExtension added " + name)
         for tree in tree_list:
             etree.dump(tree)
示例#23
0
 def removeScenarioParametersAttribute(self, key):
     if key not in self.scenarioParametersAttrib:
         if self.verbosity == 0 or self.verbosity == 1:
             print("WARNING: Attribute not found")
     else:
         self.scenarioParametersAttrib.pop(key)
         if self.verbosity == 0:
             print('INFO: Attribute deleted', key)
     if key in self.scenarioParametersPointer.attrib:
         del self.scenarioParametersPointer.attrib[key]
     utility.write_on_file(self.write, self.tree)
示例#24
0
	def setQueueLength(self, resultRequest):
		if self.queueLengthPointer is None:
			raise ValueError("ERROR: QueueLength not exist")
		result = self.queueLengthPointer.findall("./"+ utility.BPSIM + 'ResultRequest')
		self.queueLengthPointer.remove(result[-1])
		new_result = etree.SubElement(self.queueLengthPointer, utility.BPSIM + "ResultRequest")
		utility.checkResultRequest(resultRequest)
		new_result.text=resultRequest
		utility.write_on_file(self.write, self.tree)
		if self.verbosity==0:
			print("INFO: ResultRequest updated")
示例#25
0
 def setInterruptible(self, bool):
     if self.pointerInterruptible is None:
         raise ValueError("ERROR: Interruptible not exists")
     if super().checkBooleanParameter(bool) == False:
         raise ValueError("ERROR: Interruptible requires BooleanParameters")
     new_parameter = self.pointerInterruptible.findall("./" +
                                                       utility.BPSIM +
                                                       'BooleanParameter')
     new_parameter[-1].set('bool', str(bool))
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Interruptible updated")
示例#26
0
 def addSimulationModel(self):
     self.root.set('{xmlns}bpsim', "http://www.bpsim.org/schemas/1.0")
     self.registerNamespace('bpsim', "http://www.bpsim.org/schemas/1.0")
     self.relationShip = etree.SubElement(self.root,
                                          utility.BPMN2 + "relationship",
                                          attrib={"type": "BPSimData"})
     self.extension_elements = etree.SubElement(
         self.relationShip, utility.BPMN2 + "extensionElements")
     self.bpsimData = etree.SubElement(self.extension_elements,
                                       utility.BPSIM + "BPSimData")
     utility.write_on_file(self.root, self.tree)
     if self.verbosity == 0:
         print("INFO: added simulation model")
示例#27
0
	def setAvailability(self,value,validFor=None):
		if self.availabilityPointer is None:
			raise ValueError("ERROR: Availability not exist")
		if not super().checkBooleanParameter(value):
			raise ValueError("ERROR: Type of Availability is not correct, must be BooleanParameter")
		newAvailability=self.availabilityPointer.findall("./" + utility.BPSIM + 'BooleanParameter')
		newAvailability[-1].set('value',str(value))
		if validFor is not None:
			utility.checkCalendar(self.scenario.getCalendars(), validFor, self.verbosity)
			newAvailability[-1].set('validFor', validFor)
		utility.write_on_file(self.write, self.tree)
		if self.verbosity==0:
			print("INFO: Availability updated")
示例#28
0
 def addStart(self, value):
     if value is None:
         raise ValueError("ERROR: Insert value of Start")
     value = utility.getDateTimeType(value)
     self.start = {"value": value}
     parameter = etree.SubElement(self.scenarioParametersPointer,
                                  utility.BPSIM + "Start")
     parameter = etree.SubElement(parameter,
                                  utility.BPSIM + "DateTimeParameter",
                                  self.start)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Start Parameter added" + str(self.start))
示例#29
0
 def addWarmup(self, value):
     if value is None:
         raise ValueError("ERROR: Insert value of Warmup")
     value = utility.getDurationType(value)
     self.warmup = {"value": value}
     parameter = etree.SubElement(self.scenarioParametersPointer,
                                  utility.BPSIM + "Warmup")
     parameter = etree.SubElement(parameter,
                                  utility.BPSIM + "DurationParameter",
                                  self.warmup)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Warmup Parameter added" + str(self.warmup))
 def addProbability(self, value):
     self.checkControlParametersTag()
     self.typeValuePr = self.checkProbability(value)
     attrib = {"value": str(value)}
     attrib = utility.filterNoneAttributes(attrib)
     if self.probabilityPointer is None:
         self.probabilityPointer = etree.SubElement(
             self.controlPointer, utility.BPSIM + "Probability")
     new_parameter = etree.SubElement(self.probabilityPointer,
                                      utility.BPSIM + self.typeValuePr,
                                      attrib=attrib)
     utility.write_on_file(self.write, self.tree)
     if self.verbosity == 0:
         print("INFO: Probability added" + self.typeValuePr, attrib)