//Arrivals component: generates entities that will be processed by the model
function ArrivalsComponent(scheduleBlockMinutes,scheduleArray,entryDistributionArray) {
setOfComponents.push(this);
this.componentID = getNewID();
//this.componentName = "Arrivals";
this.componentName = "";
this.startBlockTime = globalSimClock;
this.currentBlockTime = globalSimClock;
this.incrementTime = scheduleBlockMinutes;
this.endBlockTime = globalSimClock + this.incrementTime;
this.entitiesScheduled = 0;
this.entitiesRemaining = 0;
this.currentEntityID = "";
this.activity = "creation";
this.scheduleIndex = -1;
this.endTime = endSimTime;
this.entryList = [];
this.entryCount = 0;
//this.nextState = "increment";
feq.newItem(globalSimClock,this,"increment"); //assume all components created at time zero
//this.dataGroup = new DisplayGroup(this.componentName,10,10,80,"#00FFFF","#FF0000","#FFFF00");
this.dataGroup = new DisplayGroup1();
this.defineDataGroup = function(x,y,vw,bc,vc,lc) {
this.dataGroup.define(this.componentName,x,y,vw,bc,vc,lc);
};
this.dataGroup.addValue(this.componentID,"Comp. ID","integer");
this.dataGroup.addValue(this.startBlockTime,"Start Time","numdec",5);
this.dataGroup.addValue(this.currentBlockTime,"CurrentTime","numdec",5);
this.dataGroup.addValue(this.endBlockTime,"End Time","numdec",5);
this.dataGroup.addValue(this.entitiesScheduled,"# Entities","integer");
this.dataGroup.addValue(this.entitiesRemaining,"# Remaining","integer");
this.dataGroup.addValue(this.currentEntityID,"Entity ID","integer");
this.dataGroup.addValue(this.activity,"Activity","text");
this.assignDisplayValues = function() {
this.dataGroup.valueList[0].value = this.componentID;
this.dataGroup.valueList[1].value = this.startBlockTime;
this.dataGroup.valueList[2].value = this.currentBlockTime;
this.dataGroup.valueList[3].value = this.endBlockTime;
this.dataGroup.valueList[4].value = this.entitiesScheduled;
this.dataGroup.valueList[5].value = this.entitiesRemaining;
this.dataGroup.valueList[6].value = this.currentEntityID;
this.dataGroup.valueList[7].value = this.activity;
};
this.drawData = function() {
this.assignDisplayValues();
this.dataGroup.drawBasic();
};
this.addToEntryList = function(entry) {
this.entryList.push(entry);
this.entryCount++;
};
this.forwardEntity = function(entity) {
//add test to ensure nextComponent is actually assigned
var dest = 0;
var test = Math.random();
while (test > entryDistributionArray[this.scheduleIndex][dest]) {
dest++;
}
if (dest > this.entryCount) {
alert("Arrival comp. tried to assign to entry with too high of an index");
}
displayProgressText("Arrivals comp. "+this.componentID+" test: "+test.toFixed(4)+" vs. "+entryDistributionArray[this.scheduleIndex][dest]);
this.entryList[dest].receiveEntity(entity);
};
this.makeEntity = function() {
//var e = generateNewEntity(this);
var e = generateNewEntity();
this.currentBlockTime = globalSimClock;
this.entitiesRemaining--;
this.currentEntityID = e.entityID; //should create function to get this
this.activity = "make entity";
displayProgressText("Arrivals comp. "+this.componentID+" generates entity: "+this.currentEntityID+" at time "+globalSimClock.toFixed(6));
//do something to send it to the entry component
this.forwardEntity(e);
//more to generate
if (this.entitiesRemaining > 0) {
var nextIndex = this.entitiesScheduled-this.entitiesRemaining;
var nextTime = this.arrivalArray[nextIndex];
var thisIndex = nextIndex-1;
var thisTime = this.arrivalArray[thisIndex];
advance(nextTime-thisTime,"makeEntity");
//advance(arrivalArray[this.entitiesScheduled-this.entitiesRemaining]-arrivalArray[this.entitiesScheduled-this.entitiesRemaining-1],"makeEntity");
}
}; //this.makeEntity
this.blockIncrement = function() { //should be called at the beginning of every time block
//get arrival count per array index
this.scheduleIndex++; //starts from -1, updates at beginning of each window so has same value through duration of window
this.entitiesScheduled = scheduleArray[this.scheduleIndex];
if (this.entitiesScheduled > 0) {
//var arrivalArray = [];
this.arrivalArray = [];
for (var i=0; i<this.entitiesScheduled; i++) {
this.arrivalArray[i] = Math.random() * scheduleBlockMinutes;
}
//sort the array
this.arrivalArray.sort(compareNumeric);
//generate the arrivals
//for (var i=0; i<this.entitiesScheduled; i++) {
// this.generateNewEntity(this,globalSimClock + this.arrivalArray[i]);
//}
feq.newItem(globalSimClock+this.arrivalArray[0],this,"makeEntity"); //assume all components created at time zero
}
displayProgressText("Arrivals comp. "+this.componentID+" generates "+this.entitiesScheduled+" new entities at time "+globalSimClock.toFixed(6));
//set values for display-------------
this.startBlockTime = globalSimClock;
this.currentBlockTime = globalSimClock;
this.endBlockTime = globalSimClock + this.incrementTime;
this.entitiesRemaining = this.entitiesScheduled;
this.currentEntityID = "";
this.activity = "generate";
//----------------------------------
if (globalSimClock + this.incrementTime >= this.endTime) {
//this.nextState = "destroy";
advance(this.incrementTime,"destroy");
} else {
advance(this.incrementTime,"increment");
}
}; //this.blockIncrement
this.destroy = function() {
displayProgressText("Arrivals comp. "+this.componentID+" terminates at time "+globalSimClock.toFixed(6));
//do something to take this element out of the global element list - setOfComponents
}; //this.destroy
this.activate = function(nextState) {
if (nextState == "makeEntity") {
this.makeEntity();
} else if (nextState == "increment") {
this.blockIncrement();
} else if (nextState == "destroy") {
this.destroy();
} else {
errorUndefinedAdvanceState(this.entityID,nextState);
}
//clearCanvas("#000000");
//this.drawData();
}
} //ArrivalsComponent