Beispiel #1
0
def read_files(instance_config_filename, config_filename):
    if instance_config_filename is None:
        instance = Instance.load_test()
    else:
        instance = Instance.load_from_file(instance_config_filename)

    # print_instance(instance)
    # print("")

    if config_filename is None:
        config = Config.load_test()
    else:
        config = Config.load_from_file(config_filename)

    return (instance, config)
Beispiel #2
0
class FitnessValues:
    file = os.path.join(dir, '..', 'instances', 'real', 'instance.txt')
    default_instance = Instance.load_from_file(file)

    def __init__(self, fitness_list):
        self.concepts_covered = fitness_list[0]
        self.difficulty = fitness_list[1]
        self.total_time = fitness_list[2]
        self.materials_balancing = fitness_list[3]
        self.learning_style = fitness_list[4]
        self.total = fitness_list[5]

    def __repr__(self):
        return f'---- FitnessValues ----\n concepts_covered: {self.concepts_covered}, difficulty: {self.difficulty}, total_time: {self.total_time}, materials_balancing: {self.materials_balancing}, learning_style: {self.learning_style}, total: {self.total} \n'

    @staticmethod
    def get_Instance(materials_concepts):
        individual = list()
        for mat in materials_concepts:
            individual.append(False if mat.sum() == 0 else True)
        return individual

    @classmethod
    def fitness_fn(cls, student_id, materials_concepts):
        individual = FitnessValues.get_Instance(materials_concepts)

        concepts_covered_objective = objective.concepts_covered_function(
            individual, cls.default_instance, student_id)
        materials_balancing_objective = objective.materials_balancing_function(
            individual, cls.default_instance, student_id)

        sum_objective = (
            cls.default_instance.concepts_covered_weight *
            concepts_covered_objective +
            FitnessValues.default_instance.materials_balancing_weight *
            materials_balancing_objective)

        return sum_objective
Beispiel #3
0
    parser_de = subparsers.add_parser('de')
    create_base_parser(parser_de)
    parser_de.add_argument('-m', '--max-velocity', type=float)
    parser_de.add_argument('--mutation-chance', type=float)
    parser_de.add_argument('-c', '--crossover-rate', type=float)
    parser_de.add_argument('-a', '--evaluator', choices=['RANDOM', 'FIXED'])

    args = parser.parse_args()

    if not args.config and not args.cost_budget and not args.max_stagnation and not args.num_iterations:
        raise Exception("No end condition specified. Use '-b', '-s' or '-i'.")

    if args.algorithm == 'nsga_ii' and args.num_objectives > 5:
        raise Exception("The problem can only have at most five objectives")

    instance = Instance.load_from_file(args.instance_file)

    config_class = config_class_dict[args.algorithm]
    if args.config:
        config = config_class.load_from_file(args.config)
    else:
        config = config_class()

    config.update_from_args(args)

    results = {
        'info': {
            'command':
            os.path.basename(sys.argv[0]) + " " + " ".join(sys.argv[1:]),
            'datetime': str(datetime.datetime.now()),
            'instance': instance,
Beispiel #4
0
        ('andre_900', 'andre/900/instance.txt'),
        ('andre_950', 'andre/950/instance.txt'),
        ('andre_1000', 'andre/1000/instance.txt'),
        ('real', 'real/test_instance.txt'),
    ]

    population_size = 1000

    quant_instances = len(filenames)
    results = np.empty((quant_instances, 24, population_size, 5))

    np.random.seed(0)
    for (i, (base, filename)) in enumerate(filenames):
        print('Reading %s' % (folder + filename))

        instance = Instance.load_from_file(folder + filename)
        timer = Timer()

        for student in range(instance.num_learners):
            print('%d / %d' % (student, instance.num_learners))

            population = np.random.randint(2,
                                           size=(population_size,
                                                 instance.num_materials),
                                           dtype=bool)
            survival_values = []
            np.apply_along_axis(fitness,
                                1,
                                population,
                                instance,
                                student,
Beispiel #5
0
    interactivity_type_frequency = Counter(instance.materials_interactivity_type)

    ############################################################################

    return {
        'instance': instance,
        'concepts_materials': instance.concepts_materials,
        'concepts_name': concepts_name,
        'concepts_quant': concepts_quant,
        'concepts_difficulty': concepts_difficulty,
        'count_histogram': count_histogram,
        'n_coocurrence_matrix': n_coocurrence_matrix,
        'coocurrence_set': coocurrence_set,
        'coocurrence_dict': coocurrence_dict,
        'quant_resource_types': quant_resource_types,
        'quant_resource_types_histogram': quant_resource_types_histogram,
        'resource_types_frequency': resource_types_frequency,
        'interactivity_level_frequency': interactivity_level_frequency,
        'interactivity_type_frequency': interactivity_type_frequency,
    }


if __name__ == '__main__':
    instance = Instance.load_from_file('instances/real/instance.txt')

    instance_data = extract_data(instance)

    with open('results/instance_stats.pickle', 'wb') as file:
        pickle.dump(instance_data, file)
Beispiel #6
0
 def instance(self, instance_file):
   self.__instance = Instance.load_from_file(instance_file)
Beispiel #7
0
import numpy as np
from acs.instance import Instance
from acs.objective import materials_balancing_function
import os

dir = os.path.dirname(__file__)

instance_file = os.path.join(dir,'instances', 'real', 'instance.txt')


individual5 = np.array([False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, True, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False])

individual23 = np.array([False, False, False, False, False, True, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, True, False, False, False, False, False, False, False, True, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, True, False, False, False, False, False, False, False, False, False,
                         False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, True, False, False, False, True, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, True, False, False, False])


instance = Instance.load_from_file(instance_file)

materials_balancing1 = materials_balancing_function(individual5, instance, 5)
print("Aluno 5 materials_balancing: ", materials_balancing1, "\n")

# materials_balancing = materials_balancing_function(individual23, instance, 23)
# print("Aluno 23 materials_balancing: ", materials_balancing)
        'instances/andre/500/instance.txt',
        'instances/real/instance.txt',
        # 'instances/test/instance_config.txt',
    ]

    difficulty_list = [1, 2, 3, 4, 5]
    style_range = np.arange(-6.5, 0, 3)
    # style_range = np.concatenate((style_range, -style_range[::-1]))
    style_range = np.concatenate((style_range, -style_range[::-1]))

    np.set_printoptions(precision=2)

    if True:
        instances = []
        for instance_file in instance_list:
            instances.append(Instance.load_from_file(instance_file))

        with open('results/instances.pickle', 'wb') as file:
            pickle.dump(instances, file)
    else:
        with open('results/instances.pickle', 'rb') as file:
            instances = pickle.load(file)

    show_general = True
    show_difficulty = True
    show_style = True
    show_concepts = True
    show_coocurrence = True

    for (num, instance) in enumerate(instances):
        print(instance_list[num])
Beispiel #9
0
import os

from acs.instance import Instance
from read.algorithm import open_results

dir = os.path.dirname(__file__)

instance = Instance.load_from_file(
    os.path.join(dir, 'instances', 'real', 'instance.txt'))

concept_coverage = instance.concepts_materials.T
objectives = instance.objectives

_acs_results = open_results('2020-01-16_real_5_100000.pickle')
_algorithm = 'de'
_repetition = 0
recommendation = _acs_results[_algorithm][0][_repetition].T  # 284x24

num_materials = concept_coverage.shape[0]
num_concepts = concept_coverage.shape[1]
num_students = recommendation.shape[1]