Package: rcplant
Recycling Plant Simulator PackageQuick startThe following code is an example of how to use this package:importrandomfromrcplantimport*defuser_sorting_function(sensors_output):# random identificationdecision={sensor_id:random.choice(list(Plastic))for(sensor_id,value)insensors_output.items()}returndecisiondefmain():# simulation parametersconveyor_length=1000# cmconveyor_width=100# cmconveyor_speed=10# cm per secondnum_containers=100sensing_zone_location_1=500# cmsensors_sampling_frequency=1# Hzsimulation_mode='training'sensors=[Sensor.create(SpectrumType.FTIR,sensing_zone_location_1),]conveyor=Conveyor.create(conveyor_speed,conveyor_length,conveyor_width)simulator=RPSimulation(sorting_function=user_sorting_function,num_containers=num_containers,sensors=sensors,sampling_frequency=sensors_sampling_frequency,conveyor=conveyor,mode=simulation_mode)elapsed_time=simulator.run()print(f'\nResults for running the simulation in "{simulation_mode}" mode:')foritem_id,resultinsimulator.identification_result.items():print(result)print(f'Total missed containers ={simulator.total_missed}')print(f'Total sorted containers ={simulator.total_classified}')print(f'Total mistyped containers ={simulator.total_mistyped}')print(f'\n{num_containers}containers are processed in{elapsed_time:.2f}seconds')if__name__=='__main__':main()You may modify theuser_sorting_functionfunction and implement new logic for sorting plastic containers.APIRPSimulationclassRPSimulation:def__init__(self,sorting_function,num_containers:int,sensors:List[Sensor],sampling_frequency:int,conveyor:Conveyor,mode:str)A manager class for the recycling plant simulator.Input parameters:sorting_function: A user-defined function that gets theoutput of the sensorsand identifies the type ofplastic, based on the given spectrum.num_containers : Number of input containers needed to be sorted.sensors : An array ofsensors.sampling_frequency: The sampling frequency of sensors. Acceptable values: 10, 5, 2, and 1 Hz. Intestingmode, increasing the sampling frequency increases added noise to spectrum.conveyor : A user-definedconveyorsystem.mode: A selector to run the simulation in eithertrainingortestingconfiguration.RPSimulation.rundefrun(self)A function to run the simulation.Outputs:RPSimulation.total_missed: Number of missed containers.RPSimulation.classified: Number of classified containers.RPSimulation.mistyped: Number of containers classified incorrectly.Returns:Amount of time required to process all containers [seconds].SensorclassSensor:def__init__(self,sensor_type:SpectrumType,location_cm:int,sensor_id:int=None)A class to define a new sensor.Input parameters:location_cm : Location of the sensor [centimeter].sensor_type : Type of the sensor [SpectrumType].sensor_id : Sensor ID, which is used insorting_functionto identify each sensor.
If no ID is provided, an ID will be generated based on the number of sensors.Sensor.createdefcreate(cls,sensor_type:SpectrumType,location:int,sensor_id:int=None)A factory method to create a newsensor.Input parameters:location : Location of the sensor [centimeter].sensor_type : Type of the sensor [SpectrumType].sensor_id : Sensor ID, which is used insorting_functionto identify each sensor.
If no ID is provided, an ID will be generated based on the number of sensors.ReturnsAsensorobject.Sensor.reset_numdefreset_num(cls)A class method to reset the number of created sensors. This would be helpful if you also want to reset IDs assigned to newly created sensors.Sensor.id@propertydefid(self)Returns Sensor's ID.ConveyorclassConveyor:def__init__(self,speed_cm_per_second:int,dimension:ConveyorDimension)A class to define a new conveyor.Input parameters:speed_cm_per_second : Speed of the conveyor [centimeter per second].dimension : Dimensions of the conveyor in centimeter.Conveyor.createdefcreate(cls,speed_cm_per_second:int,length:int,width:int)A factory method to create a newconveyor.Input parameters:speed_cm_per_second : Speed of the conveyor [centimeter per second].length : Length of the conveyor in centimeter.width : Width of the conveyor in centimeter.ReturnsAconveyorobject.Sorting_functiondefsorting_function(sensors_output)A user-defined function that identifies the type of plastic, based on the given spectrum.Input parameters:sensors_output : A dictionary with sensors information. The keys are the id of each sensor.{sensor.id:{'type':type,'location':location,'spectrum':spectrum,}}Return value:plastic_type dict:Plasticdecision={sensor_id:plastic_type}PlasticclassPlastic(enum.Enum):HDPE='HDPE'LDPE='LDPE'PP='PP'PS='PS'PC='PC'PVC='PVC'Polyester='Polyester'PET='PET'PU='PU'Blank='background'An enum for all types of plasticsSpectrumTypeclassSpectrumType(enum.Enum):FTIR='FTIR'Raman='Raman'An enum for all types of sensors