📄 numberofcustomerparametricanalysis.java
字号:
double sum = 0;
Vector classSet = classDef.getClosedClassKeys();
values = new ValuesTable(classDef,classSet,numberOfSteps);
//calculate the proportion between classes populations
double[] betas = new double[classSet.size()];
double totalPop = classDef.getTotalCloseClassPopulation();
for (int i=0;i<classSet.size();i++) {
double thisPop = classDef.getClassPopulation(classSet.get(i)).doubleValue();
betas[i] = thisPop/totalPop;
}
for (int i=0;i<numberOfSteps;i++) {
thisStep = (int)sum;
totalPop = ((Integer)validParameterValues.get(thisStep)).intValue();
for (int j=0;j<classSet.size();j++) {
double thisClassNextNumberOfJobs = totalPop*betas[j];
int value = (int) (thisClassNextNumberOfJobs);
((ValuesTable)values).setValue(classSet.get(j),value);
}
sum += p;
}
originalValues = new Vector(classSet.size());
for (int i=0;i<classSet.size();i++) {
Object thisClass = classSet.get(i);
Integer thisValue = new Integer(classDef.getClassPopulation(thisClass).intValue());
((Vector)originalValues).add(thisValue);
}
}
}
/**
* Restore the original values of population
*/
public void restoreOriginalValues() {
if (singleClass) {
classDef.setClassPopulation((Integer)originalValues,classKey);
}
else {
Vector vals = (Vector)originalValues;
Vector classSet = classDef.getClosedClassKeys();
for (int i=0;i<classSet.size();i++) {
Object thisClass = classSet.get(i);
Integer thisVal = new Integer(((Integer)vals.get(i)).intValue());
classDef.setClassPopulation(thisVal,thisClass);
}
}
simDef.manageJobs();
//modified = false;
}
/**
* Checks if the PA model is still coherent with simulation model definition. If
* the <code>autocorrect</code> variable is set to true, if the PA model is no more
* valid but it can be corrected it will be changed.
*
* @param autocorrect if true the PA model will be autocorrected
*
* @return 0 - If the PA model is still valid <br>
* 1 - If the PA model is no more valid, but it will be corrected <br>
* 2 - If the PA model can be no more used
*/
public int checkCorrectness(boolean autocorrect) {
int code = 0;
Vector closeClasses = classDef.getClosedClassKeys();
if (closeClasses.isEmpty()) code = 2; //This PA model can be no more used
else {
//if is single class...
if (isSingleClass()) {
// ... and the selected close class is no more avaible
if (!closeClasses.contains(classKey)) {
code = 1;
if (autocorrect) {
classKey = closeClasses.get(0); //change the reference class
int totalPop = classDef.getTotalCloseClassPopulation();
double minFinal = totalPop + 1;
initialValue = totalPop;
if (finalValue < minFinal) finalValue = minFinal;
numberOfSteps = searchForAvaibleSteps();
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
}
// else check that the initial value equals the number of jobs belonging to the reference class
else {
int totalPop = classDef.getTotalCloseClassPopulation();
double minFinal = totalPop + 1;
if (initialValue != totalPop) {
code = 1;
if (autocorrect){
initialValue = totalPop;
if (finalValue < minFinal ) { //the initial value was changed,
finalValue = minFinal; //so change the final value and
}
numberOfSteps = searchForAvaibleSteps(); //number of steps
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
}
}
}
else {
int totalPop = classDef.getTotalCloseClassPopulation();
double minFinal;
if (classDef.getClosedClassKeys().size() == 1) minFinal = totalPop + 1;
else minFinal = totalPop*2 + 1;
// if the total number of job has changed
if (initialValue != totalPop) {
code = 1;
if (autocorrect) {
initialValue = totalPop;
if (finalValue < minFinal ) { //the initial value was changed,
finalValue = minFinal; //so change the final value and
}
numberOfSteps = searchForAvaibleSteps(); //number of steps
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
}
else {
Vector temp = validParameterValues;
int temp2 = searchForAvaibleSteps();
//if the total nmber job equals initialValue, but the
//validParameterValues is different from the old one
//it means that something was changed
if (!temp.equals(validParameterValues)) {
code = 1;
if (autocorrect) {
//set the new number of steps
numberOfSteps = temp2;
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
else validParameterValues = temp;
}
}
if (closeClasses.size() == 1) {
code = 1;
if (autocorrect) {
singleClass = true;
classKey = closeClasses.get(0);
}
}
}
}
//modified = false;
//lastCode = code;
return code;
//}
}
/**
* Returns the values assumed by the varying parameter
*
* @return a Vector containing the values assumed by the varying parameter
*/
public Vector getParameterValues() {
Vector assumedValues = new Vector(numberOfSteps);
if (singleClass) {
Vector temp = (Vector)values;
double initial = ((Integer)originalValues).doubleValue();
double sum = classDef.getTotalCloseClassPopulation() - initial;
for (int i=0; i<numberOfSteps; i++) {
double val = ((Integer)(temp.get(i))).doubleValue() + sum;
assumedValues.add( new Double(val) );
}
}
else {
ValuesTable temp = (ValuesTable)values;
int classNumber = temp.getNumberOfClasses();
for (int i=0; i<numberOfSteps; i++) {
double sum = 0;
for (int j=0; j<classNumber; j++) {
Object thisClass = classDef.getClosedClassKeys().get(j);
sum += temp.getValue(thisClass,i);
}
assumedValues.add(new Double(sum));
}
}
return assumedValues;
}
/**
* Get the reference class name
*
* @return the name of the class
*/
public String getReferenceClassName() {
return classDef.getClassName(classKey);
}
/**
* Gets a TreeMap containing for each property its value. The supported properties are
* defined as constants inside this class.
* @return a TreeMap containing the value for each property
*/
public Map getProperties() {
TreeMap properties = new TreeMap();
properties.put(TYPE_PROPERTY,getType());
properties.put(TO_PROPERTY,Double.toString(finalValue));
properties.put(STEPS_PROPERTY,Integer.toString(numberOfSteps));
properties.put(IS_SINGLE_CLASS_PROPERTY,Boolean.toString(singleClass));
if (singleClass) properties.put(REFERENCE_CLASS_PROPERTY,classDef.getClassName(classKey));
return properties;
}
/**
* Sets the value for the specified property. The supported properties are: <br>
* - TO_PROPERTY <br>
* - STEPS_PROPERTY <br>
* - IS_SINGLE_CLASS_PROPERTY <br>
* - REFERENCE_CLASS_PROPERTY
* @param propertyName the name of the property to be set
* @param value the value to be set
*/
public void setProperty (String propertyName, String value) {
if (propertyName.equals(TO_PROPERTY )) {
finalValue = Double.parseDouble(value);
}
else if (propertyName.equals(STEPS_PROPERTY )) {
numberOfSteps = Integer.parseInt(value);
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
else if (propertyName.equals(IS_SINGLE_CLASS_PROPERTY )) {
singleClass = Boolean.valueOf(value).booleanValue();
}
else if (propertyName.equals(REFERENCE_CLASS_PROPERTY )) {
classKey = classDef.getClassByName(value);
}
simDef.setSaveChanged();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -