📄 blockingregion.java
字号:
this.maxCapacityPerClass = null;
for (int c = 0; c < classNumber; c++) {
//no class constraint
classConstraintDefined[c] = false;
}
} else {
//class constraint defined
//copy constraints values
this.maxCapacityPerClass = maxCapacityPerClass;
for (int c = 0; c < classNumber; c++) {
if (maxCapacityPerClass[c] == -1) {
//no constraints on this class
classConstraintDefined[c] = false;
} else {
classConstraintDefined[c] = true;
}
}
}
//init actual occupation per class
this.actualOccupationPerClass = new double[classNumber];
this.classBlocked = new boolean[classNumber];
for (int c = 0; c < classNumber; c++) {
//init occupation
actualOccupationPerClass[c] = 0;
//init class status
this.classBlocked[c] = false;
}
//------------------WEIGHTED CONSTRAINT--------------------//
weightedConstraintDefined = true;
//copy class weights
this.classWeights = classWeights;
//------------------DROP PROPERTIES-----------------------//
dropClass = new boolean[classNumber];
dropClass = drop;
}
//-----------------------CONSTRAINTS METHODS---------------------------\\
/** True if there is a global constraint */
public boolean hasGlobalConstraint() {
return globalConstraintDefined;
}
/** True if the class is subjectedto a class constraint */
public boolean hasClassConstraint(JobClass jobClass) {
return classConstraintDefined[jobClass.getId()];
}
/** True if the region has a global weighted constraint (constraint is shared,
* but different classes have different weights)
* @return True if the region has a global weighted constraint
*/
public boolean hasWeightedConstraint() {
return weightedConstraintDefined;
}
/** Gets the number of jobs currently inside the blocking region */
public double getActualOccupation() {
return actualOccupation;
}
/** Gets the number of jobs of the specified class currently inside the blocking region
* @param jobClass the specified class
*/
public double getActualOccupation(JobClass jobClass) {
if (jobClass != null) {
return actualOccupationPerClass[jobClass.getId()];
} else {
return 0;
}
}
/** Increases both the number of total jobs currently inside the region
* and also the number of jobs of the specified class currently inside
* the region.
*/
public void increaseOccupation(JobClass jobClass) {
int c = jobClass.getId();
actualOccupation += classWeights[c];
actualOccupationPerClass[c] += classWeights[c];
return;
}
/** Decreases the number of jobs currently inside the region */
public void decreaseOccupation(JobClass jobClass) {
int c = jobClass.getId();
actualOccupation -= classWeights[c];
actualOccupationPerClass[c] -= classWeights[c];
return;
}
/** Gets the drop property relative to a class constraint: if
* true, jobs in excess of this class will be dropped */
public boolean getClassDrop(JobClass jobClass) {
return dropClass[jobClass.getId()];
}
/** Gets the drop property relative to a class constraint: if
* true, jobs in excess of this class will be dropped */
public boolean getClassDrop(int classIndex) {
return dropClass[classIndex];
}
/**
* Tells whether the region is blocked for this class or
* has enough place for a job of this class.
* @return true if blocked, false if other capacity is available
*/
public boolean isBlocked(JobClass jobClass) {
int id = jobClass.getId();
if (globalConstraintDefined) {
if ((actualOccupation + classWeights[id]) > maxCapacity) {
//globally blocked
return true;
}
}
if (classConstraintDefined[jobClass.getId()]) {
if ((actualOccupationPerClass[id] + classWeights[id])
> maxCapacityPerClass[id]) {
//class blocked
return true;
}
}
return false;
}
//-------------------- end CONSTRAINTS METHODS---------------------------\\
/** Gets the name of the blocking region */
public String getName() {
return name;
}
/**Gets the names of the region nodes */
public String[] getRegionNodeNames() {
return regionNodeNames;
}
/**
* Finds and sets the netNode objects using the node names
*/
private void findRegionNodes() {
//nodes of ther region must be found, using their names
network = sim.getNetwork();
regionNodes = new NetNode[regionNodeNames.length];
for (int i = 0; i < regionNodeNames.length; i++) {
//TODO: check wrong names...?
regionNodes[i] = network.getNode(regionNodeNames[i]);
}
}
/**
* Tells whether a node is contained in the blocking region
* @param nodeName the name of the node
* @return true if the specified node is contained in the region
*/
public boolean belongsToRegion(String nodeName) {
for (int i = 0; i < regionNodeNames.length; i++) {
if (regionNodeNames[i].equalsIgnoreCase(nodeName)) {
//the specified node is contained in the blocking region
return true;
}
}
//the specified node is not contained in the blocking region
return false;
}
/**
* Tells whether a node is contained in the blocking region
* @param node the NetNode object
* @return true if the specified node is contained in the region
*/
public boolean belongsToRegion(NetNode node) {
if (network == null) {
//if network hasn't been set
//nodes of ther region must be found, using their names
findRegionNodes();
}
for (int i = 0; i < regionNodes.length; i++) {
if (regionNodes[i] == node) {
//the specified node is contained in the blocking region
return true;
}
}
//the specified node is not contained in the blocking region
return false;
}
/**
* Returns a node, if contained in the blocking region
* @param nodeName the name of the node
* @return the NetNode object if the specified node is contained in the region,
* null otherwise
*/
public NetNode getRegionNode(String nodeName) {
if (network == null) {
//before searching a particular node for the first time,
//nodes of ther region must be found, using their names
findRegionNodes();
}
for (int i = 0; i < regionNodeNames.length; i++) {
if (regionNodeNames[i].equalsIgnoreCase(nodeName)) {
//the specified node is contained in the blocking region
//returns the corresponding NetNode object
return regionNodes[i];
}
}
//the specified node is not contained in the blocking region
//returns null
return null;
}
/**
* Gets the fictitious station that controls arrivals to the blocking region
* @return the fictitious station that controls arrivals to the blocking region
*/
public NetNode getInputStation() {
return inputStation;
}
/**
* Sets the input station of the blocking region
* @param inputStation the input station of the blocking region
*/
public void setInputStation(NetNode inputStation) {
this.inputStation = inputStation;
}
/**
* @return Returns the classWeights.
*/
public double[] getClassWeights() {
return classWeights;
}
/**
* @return Returns the maxCapacity.
*/
public double getMaxCapacity() {
return maxCapacity;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -