Beispiel #1
0
	def antTour(self):
		# The job sequence build by the ant
		antSched=Schedule(self.jsspInst)
		# Initialize the roulette, which is a dictionary with JobId and the probability interval: (jobId:[pStart,pEnd])
		jobRoulette = dict([x, [0.0,0.0]] for x in range(self.jsspInst.jobs))

		# Defining the first job: randomized(70%) or best schedule(30%).
		if len(self.bestSchedule.jobSched) > 0 and random.random() > 0.7:
			currJob = self.bestSchedule.jobSched[0]   # The same first position of the last best schedule
		else:
			currJob = int((random.random() * 1000) % self.jsspInst.jobs)
		del jobRoulette[currJob]
		antSched.addJob(currJob)

		# Select next jobs
		while (len(jobRoulette) > 0):
			self.buildRoulette(jobRoulette, currJob)
			
			bingo = random.random()
			for jId,prob in jobRoulette.iteritems():
				if prob[0] < bingo < prob[1]:
					currJob = jId
					break
			del jobRoulette[currJob]
			antSched.addJob(currJob)

		self.antScheds.append(antSched)
		return
    def testAddJob(self):
        # Testing the presentation istance
        jsspInst = JSSPInstance("../jssp_instances/transparencia.txt")
        sched = Schedule(jsspInst)

        status = sched.addJob(0)
        self.assert_(status == True, "Error job 0")

        status = sched.addJob(1)
        self.assert_(status == True, "Error job 1")

        status = sched.addJob(1)
        self.assert_(status == False, "Duplicated jobId")

        status = sched.addJob(6)
        self.assert_(status == False, "Invalid jobId(0-2): 6")

        status = sched.addJob(2)
        self.assert_(status == True, "Error job 2")

        status = sched.addJob(3)
        self.assert_(status == False, "Maximum jobs exceeded")

        self.assert_(sched.jobSched[0] == 0, "jobSched 0")
        self.assert_(sched.jobSched[1] == 1, "jobSched 1")
        self.assert_(sched.jobSched[2] == 2, "jobSched 2")
        return
    def testObjectiveFunction(self):
        # Testing the presentation istance
        jsspInst = JSSPInstance("../jssp_instances/transparencia.txt")

        sched = Schedule(jsspInst)
        sched.addJob(0)
        sched.addJob(1)
        sched.addJob(2)
        self.assert_(sched.makespan == 30, "Makespan: %i" % sched.makespan)

        sched = Schedule(jsspInst)
        sched.addJob(0)
        sched.addJob(2)
        sched.addJob(1)
        self.assert_(sched.makespan == 34, "Makespan: %i" % sched.makespan)

        sched = Schedule(jsspInst)
        sched.addJob(1)
        sched.addJob(0)
        sched.addJob(2)
        self.assert_(sched.makespan == 29, "Makespan: %i" % sched.makespan)

        sched = Schedule(jsspInst)
        sched.addJob(2)
        sched.addJob(1)
        sched.addJob(0)
        self.assert_(sched.makespan == 26, "Makespan: %i" % sched.makespan)

        # Testing the Abz5 istance. Makespan value sent from e-mail list
        jsspInst = JSSPInstance("../jssp_instances/abz5.txt")

        sched = Schedule(jsspInst)
        sched.addJob(7)
        sched.addJob(0)
        sched.addJob(2)
        sched.addJob(9)
        sched.addJob(6)
        sched.addJob(8)
        sched.addJob(4)
        sched.addJob(5)
        sched.addJob(1)
        sched.addJob(3)
        self.assert_(sched.makespan == 1544, "Makespan: %i" % sched.makespan)

        # Prof. Valdisio said that this is the best known makespan: 1544. But we found 1731.
        sched = Schedule(jsspInst)
        sched.addJob(5)
        sched.addJob(9)
        sched.addJob(3)
        sched.addJob(4)
        sched.addJob(6)
        sched.addJob(2)
        sched.addJob(7)
        sched.addJob(0)
        sched.addJob(1)
        sched.addJob(8)
        self.assert_(sched.makespan == 1731, "Makespan: %i" % sched.makespan)

        # Testing the Car5 istance. Makespan value sent from e-mail list
        jsspInst = JSSPInstance("../jssp_instances/Car5.txt")

        sched = Schedule(jsspInst)
        sched.addJob(4)
        sched.addJob(3)
        sched.addJob(2)
        sched.addJob(0)
        sched.addJob(5)
        sched.addJob(1)
        sched.addJob(8)
        sched.addJob(6)
        sched.addJob(9)
        sched.addJob(7)
        self.assert_(sched.makespan == 7822, "Makespan: %i" % sched.makespan)
        return