Search code examples
javasimulationinstantiationanylogic

How to Instantiate an Anylogic block/Object (INode)


I have set up different product types that go through processes and end up in a Warehouse. Now i want to decide where to put it using say a moveTo block. So i need to get an INode (a rectangular node) for the product. So i want to write a function that takes the product type (its an Option List type) and returns the INode my function looks like: See this image for function

The Code:

INode location = new INode();
switch(product){
	case GREEN: location = sortGreen; break;
	case RED: location = sortRed; break;
	case BLUE: location = sortBlue; break;
	case MAGENTA: location = sortMagenta; break;
	case YELLOW: location = sortYellow; break;
	}
return location;
This generates an error:

 "Cannot Instantiate type INode"

The manual doesnt have much about using blocks and Anylogic Objects in code. Can anyone assist in Instantiating this object?


Solution

  • This will do the trick... No need to instantiate in the beginning.

    switch(product){
        case GREEN: return sortGreen;
        case RED: return sortRed;
        case BLUE: return sortBlue;
        case MAGENTA: return sortMagenta;
        case YELLOW: return sortYellow;
    }
    return null;