All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.optaplanner.examples.travelingtournament.persistence.TravelingTournamentSolutionFileIO Maven / Gradle / Ivy

Go to download

OptaPlanner solves planning problems. This lightweight, embeddable planning engine implements powerful and scalable algorithms to optimize business resource scheduling and planning. This module contains the examples which demonstrate how to use it in a normal Java application.

There is a newer version: 9.44.0.Final
Show newest version
package org.optaplanner.examples.travelingtournament.persistence;

import java.io.File;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.optaplanner.examples.common.persistence.AbstractJsonSolutionFileIO;
import org.optaplanner.examples.travelingtournament.domain.Team;
import org.optaplanner.examples.travelingtournament.domain.TravelingTournament;

public class TravelingTournamentSolutionFileIO extends AbstractJsonSolutionFileIO {

    public TravelingTournamentSolutionFileIO() {
        super(TravelingTournament.class);
    }

    @Override
    public TravelingTournament read(File inputSolutionFile) {
        TravelingTournament travelingTournament = super.read(inputSolutionFile);

        var teamsById = travelingTournament.getTeamList().stream()
                .collect(Collectors.toMap(Team::getId, Function.identity()));
        /*
         * Replace the duplicate team instances in the distanceToTeamMap by references to instances from
         * the teamList.
         */
        for (Team team : travelingTournament.getTeamList()) {
            var newTravelDistanceMap = deduplicateMap(team.getDistanceToTeamMap(),
                    teamsById, Team::getId);
            team.setDistanceToTeamMap(newTravelDistanceMap);
        }
        return travelingTournament;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy