from DEVS import *
from infinity import INFINITY

import random, math, sys, getopt

def termination_condition(time, model, transitioned):
    time = time[0]
    return False
        
class ParticleState:
    def __init__(self):
        pass

class Particle(AtomicDEVS):
    def __init__(self, particle_id):
        AtomicDEVS.__init__(self, "Particle[%i]" % particle_id)
        self.state = ParticleState()
        self.port1 = self.addOutPort("OPort1")
        self.port2 = self.addOutPort("OPort2")
        self.port3 = self.addOutPort("OPort3")
        self.iport1 = self.addInPort("IPort1")
        self.iport2 = self.addInPort("IPort2")
        self.iport3 = self.addInPort("IPort3")
        self.iport4 = self.addInPort("IPort4")
    
    def timeAdvance(self):
        return 1.0
    
    def outputFnc(self):
        output = {self.port1: "Hello", self.port2: "HelloAgain", self.port3: "HelloOnceMore"}
        return output
    
    def intTransition(self):
        return self.state
    
    def extTransition(self, inputs):
        return self.state

class Root(CoupledDEVS):
    def __init__(self):
        CoupledDEVS.__init__(self, "Field")
        
        self.port1 = self.addOutPort("OPort1")
        self.particle1 = self.addSubModel(Particle(1))
        self.particle2 = self.addSubModel(Particle(2))
        self.connectPorts(self.particle1.port1, self.particle2.iport1)
        self.connectPorts(self.particle1.port2, self.particle2.iport2)
        self.connectPorts(self.particle1.port2, self.particle2.iport3)
        self.connectPorts(self.particle1.port1, self.particle2.iport4)