    001package org.cpsolver.ifs.assignment;
    002
    003import java.util.Arrays;
    004
    005import org.cpsolver.ifs.assignment.context.InheritedAssignmentContextHolder;
    006import org.cpsolver.ifs.model.Value;
    007import org.cpsolver.ifs.model.Variable;
    008import org.cpsolver.ifs.solution.Solution;
    009
    010public class InheritedAssignmentArray<V extends Variable<V, T>, T extends Value<V, T>> extends AssignmentArray<V, T> implements InheritedAssignment<V, T> {
    011    private Assignment<V, T> iParent;
    012    private long iVersion = -1;
    013    private int iIndex = -1;
    014
    015    public InheritedAssignmentArray(Solution<V, T> parent, int index) {
    016        super(new InheritedAssignmentContextHolder<V, T>(index, parent.getIteration()));
    017        iIndex = index;
    018        iAssignments = Arrays.copyOf(((AssignmentArray<V, T>)parent.getAssignment()).iAssignments, parent.getModel().variables().size());
    019        iIteration = Arrays.copyOf(((AssignmentArray<V, T>)parent.getAssignment()).iIteration, parent.getModel().variables().size());
    020    }
    021
    022    @Override
    023    public int getIndex() {
    024        return iIndex;
    025    }
    026
    027    @Override
    028    public Assignment<V, T> getParentAssignment() {
    029        return iParent;
    030    }
    031
    032    @Override
    033    public long getVersion() {
    034        return iVersion;
    035    }
    036}