Ejemplo n.º 1
0
def main():

    # Logging: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
    # or maybe http://www.patricksoftwareblog.com/python-logging-tutorial/

    logger = logging.getLogger(__name__)
    logging.basicConfig(level=logging.INFO)
    logging.info('Start reading database')
    # read database here
    records = {'john': 55, 'tom': 66}
    logger.debug('Records: %s', records)
    logger.info('Updating records ...')
    # update records here
    logger.info('Finish updating records')

    # setupLogging()

    # Make spacecrafts
    Cygnus1 = Cygnus()
    spacecraftsDict["Cygnus1"] = Cygnus1
    VerneATV1 = VerneATV()
    spacecraftsDict["VerneATV1"] = VerneATV1
    Progress1 = Progress()
    spacecraftsDict["Progress1"] = Progress1
    Kounotori1 = Kounotori()
    spacecraftsDict["Kounotori1"] = Kounotori1

    print(spacecraftsDict)

    with open('Cargolist1.json') as cargolistFile1:
        cargolist1 = json.load(cargolistFile1)

    ### SORT CARGOLIST ###
    # Unpack
    cargolist1 = sortmeth.unpack(cargolist1)

    # Weight
    # cargolist1 = sortmeth.sortWeight(cargolist1)

    # Density
    cargolist1 = sortmeth.sortDensity(cargolist1)

    # Random
    # cargolist1 = sortmeth.sortRandom(cargolist1)

    # cargoOnlyWeightLeftAircraft(cargolist1)
    cargoMostDensityLeftAircraft(cargolist1)
    # cargoRandom(cargolist1)

    #inf.infoCargoGround(cargolist1)

    # Display Spacecrafts
    for Spacecraft in spacecraftsList:
        Spacecraft.displaySpacecraft()
Ejemplo n.º 2
0
def main():

    # Make spacecrafts
    # heel makkelijk aan te passen hoe veel je van elk soort wil maken
    Cygnuslist = [Cygnus() for i in range(1)]
    spacecraftsList.extend(Cygnuslist)
    VerneATVlist = [VerneATV() for i in range(1)]
    spacecraftsList.extend(VerneATVlist)
    Progresslist = [Progress() for i in range(1)]
    spacecraftsList.extend(Progresslist)
    Kounotorilist = [Kounotori() for i in range(1)]
    spacecraftsList.extend(Kounotorilist)

    with open('Cargolist1.json') as cargolistFile1:
        cargolist1 = json.load(cargolistFile1)

    ### SORT CARGOLIST ###
    # Unpack
    cargolist1 = sortmeth.unpack(cargolist1)

    # Weight
    # cargolist1 = sortmeth.sortWeight(cargolist1)

    # Density
    cargolist1 = sortmeth.sortDensity(cargolist1)

    # Random
    # cargolist1 = sortmeth.sortRandom(cargolist1)

    # cargoOnlyWeightLeftAircraft(cargolist1)
    cargoMostDensityLeftAircraft(cargolist1)
    # cargoRandom(cargolist1)

    # Display Spacecrafts
    for Spacecraft in spacecraftsList:
        Spacecraft.displaySpacecraft()

    inf.infoCargoGround(cargolist1)

    hillClimber(cargolist1, spacecraftsList)

    # Display Spacecrafts
    for Spacecraft in spacecraftsList:
        Spacecraft.displaySpacecraft()

    # ter vergelijking na hillclimber
    inf.infoCargoGround(cargolist1)
Ejemplo n.º 3
0
def main():


	setupLogging()

	# Make spacecrafts
	Cygnus1 = Cygnus()
	spacecraftsList.append(Cygnus1)
	VerneATV1 = VerneATV()
	spacecraftsList.append(VerneATV1)
	Progress1 = Progress()
	spacecraftsList.append(Progress1)
	Kounotori1 = Kounotori()
	spacecraftsList.append(Kounotori1)

	with open('Cargolist1.json') as cargolistFile1:    
	    cargolist1 = json.load(cargolistFile1)

		### SORT CARGOLIST ###
	# Unpack
	cargolist1 = sortmeth.unpack(cargolist1)

	# Weight
	# cargolist1 = sortmeth.sortWeight(cargolist1)

	# Density
	cargolist1 = sortmeth.sortDensity(cargolist1)

	# Random
	# cargolist1 = sortmeth.sortRandom(cargolist1)
	


	# cargoOnlyWeightLeftAircraft(cargolist1)
	cargoMostDensityLeftAircraft(cargolist1)
	# cargoRandom(cargolist1)

	#inf.infoCargoGround(cargolist1)

	# Display Spacecrafts
	for Spacecraft in spacecraftsList:
		Spacecraft.displaySpacecraft()

	hillClimber(cargolist1, spacecraftsList)
Ejemplo n.º 4
0
def main():

    # load cargolist
    with open('cargolist1.json') as cargolist1:
        cargolist1 = json.load(cargolist1)

    for j in range(3):

        # Make spacecrafts
        # heel makkelijk aan te passen hoe veel je van elk soort wil maken
        Cygnuslist = [
            Spacecraft("Cygnus" + str(i), 18.9, 2000, 0, "USA")
            for i in range(1)
        ]
        spacecraftsFleet.extend(Cygnuslist)

        VerneATVlist = [
            Spacecraft("VerneATV" + str(i), 13.1, 2300, 0, "Europe")
            for i in range(1)
        ]
        spacecraftsFleet.extend(VerneATVlist)

        Progresslist = [
            Spacecraft("Progress" + str(i), 7.6, 2400, 0, "Russia")
            for i in range(1)
        ]
        spacecraftsFleet.extend(Progresslist)

        Kounotorilist = [
            Spacecraft("Kounotori" + str(i), 14, 5200, 0, "Japan")
            for i in range(1)
        ]
        spacecraftsFleet.extend(Kounotorilist)

        # edit cargolist
        cargolist1 = sortmeth.unpack(cargolist1)

        # hillClimber(cargolist, cargolistordering, spacecraftordering, spacecraftsFleet)
        hillClimber(cargolist1, 'density', 'density', "m3")
Ejemplo n.º 5
0
import json
from pyeasyga import pyeasyga
import sortingmethods as sortmeth

weightcap, volumecap = 5200, 14

# setup data
with open('cargolist1.json') as cargolist:
    data = json.load(cargolist)

data = sortmeth.unpack(data)
data = sortmeth.sortDensity(data)
data = data

ga = pyeasyga.GeneticAlgorithm(data)  # initialise the GA with data
ga.population_size = 200  # increase population size to 200 (default value is 50)


# define a fitness function
def fitness(individual, data):
    weight, volume, price = 0, 0, 0
    for (selected, item) in zip(individual, data):
        if selected:
            weight += item["kgs"]
            volume += item["m3"]
            price += item["m3"]
    if weight > weightcap or volume > volumecap:
        price = 0
    return price

Ejemplo n.º 6
0
def main():

    # Open resultloggerfile
    with open('GreedyDensity-Hillclimber.csv', 'ab') as csvFile:
        writer = csv.writer(csvFile, delimiter=',')
        writer.writerow([
            'Algorithm(s)', 'Round', 'Iteration', 'Swaps', 'KgsOnGround',
            'M3OnGround'
        ])

        for j in range(1):
            # load cargolist
            with open('cargolist1.json', 'r') as cargolist1:
                cargolist1 = json.load(cargolist1)

            # Make spacecrafts
            # heel makkelijk aan te passen hoe veel je van elk soort wil maken
            Cygnuslist = [
                Spacecraft("Cygnus" + str(i), 18.9, 2000, 0, "USA")
                for i in range(1)
            ]
            spacecraftsFleet.extend(Cygnuslist)

            VerneATVlist = [
                Spacecraft("VerneATV" + str(i), 13.1, 2300, 0, "Europe")
                for i in range(1)
            ]
            spacecraftsFleet.extend(VerneATVlist)

            Progresslist = [
                Spacecraft("Progress" + str(i), 7.6, 2400, 0, "Russia")
                for i in range(1)
            ]
            spacecraftsFleet.extend(Progresslist)

            Kounotorilist = [
                Spacecraft("Kounotori" + str(i), 14, 5200, 0, "Japan")
                for i in range(1)
            ]
            spacecraftsFleet.extend(Kounotorilist)

            # edit cargolist
            cargolist2 = sortmeth.unpack(cargolist1)

            # # Metadata to use for logging (metadata is a dict with the total m3, kgs, number of cargo on ground)
            # # DIT GAAN WE LATER NOG VERANDEREN, IS NU TIJDELIJK OM LOGGER TE TESTEN
            metadata1 = (cargo for cargo in cargolist1
                         if cargo["id"] == "MetaDataOnGround").next()
            metadata2 = (cargo for cargo in cargolist2
                         if cargo["id"] == "MetaDataOnGround").next()

            # # Write to output a new round of testing a combination of algorithms
            # writer.writerow(['GreedyDensity-Hillclimber',j, None, None, metadata['kgs'], metadata['m3']])

            # hillClimber(cargolist, cargolistordering, spacecraftordering, spacecraftsFleet)
            hillClimber(cargolist2, 'density', 'density', "m3", csvFile,
                        writer, j)
            # hillClimber(cargolist1, 'random', 'random', "m3")
            # anneal(cargolist1, 'density', 'density', "m3")
            # anneal(cargolist1, 'random', 'random', "m3")

            # 	# Display Spacecrafts
            # for Spacecraft in spacecraftsFleet:
            # 	Spacecraft.displaySpacecraft()

            # ter vergelijking na hillclimber
            #inf.infoCargoGround(cargolist1)

        # Close CSV File
        csvFile.close()