if SIMULATION:
	Prob = imp.importProb(PRISMFILENAME,NPAR)

	for run in range(RUNS):
		#sim((run, Prob, P))
		print "-> RUN "+str(run)
		# controller initial state
		ci = L.names[random.choice(L.S)]
		# environment initial state (not observable)
		ei = 'tl' #M.names[random.choice([M.inv_names['tl'],M.inv_names['tr']])]

		init = { s for s in P.S if P.L.names[s[0]] == ci }
		distr = {(0,M.inv_names['tl']):0.5, (0,M.inv_names['tr']):0.5}
		# initialize belief state
		b = belief.belief(P,P.Z,init=distr)
		# first observation
		o = func.weighted_choice(
			P.Z[((L.inv_names[ci]),(M.inv_names[ei]))])
		# belief update
		print 'init: ', b.d
		b.update(obs=o)
		if PRINT:
			print 'b(s):',b.d[((L.inv_names[ci]),(M.inv_names[ei]))] \
				if ((L.inv_names[ci]),(M.inv_names[ei])) in b.d else 0

		for it in range(MAXITER):
			print 'belief: ', b.d
			# scheduled choice
			a = None
			if SCHEDULER == 0:
    print "--> EXECUTING: " + command
    start = time.time()
    os.system(command)
    end = time.time()
    print "--> DONE (time: "+ str(end-start) + ")"

# === ONLINE ===

if SIMULATION:
    Prob = imp.importProb(tempFileName,NPAR)
    # controller initial state
    ci = (1,1)
    # environment initial state (non observable)
    ei = M.names[random.choice(M.S)]
    # initialize belief state
    b = belief.belief(P,P.Z)

    #print "ci:"+str(ci),"ei:" + str(ei)
    rob.print_grid(ci,ei,DIM,pause=PAUSE)
    for i in range(MAXITER):
        # scheduled choice
        #a = random.choice(cs.L.A)
        maximum = -1
        act_max = None
        for a in L.A:
            ba = b.returnUpdate(act=a)
            val = sched.avgMinScheduler(ba,Prob,P)
            #val = rob.opt(ba,Prob,P)
            if round(val,10) == round(maximum,10):
                act_max.add(a)
                print 'EQ act:',a,' - val:',val