001 package net.sf.cpsolver.studentsct.model; 002 003 import java.util.Enumeration; 004 import java.util.Vector; 005 006 /** 007 * Representation of a configuration of an offering. A configuration contains id, name, an offering and a list of subparts. 008 * <br><br> 009 * Each instructional offering (see {@link Offering}) contains one or more configurations. 010 * Each configuration contain one or more subparts. Each student has to take a class of each subpart of one of the 011 * possible configurations. Some restrictions might be defined using reservations (see {@link net.sf.cpsolver.studentsct.constraint.Reservation}). 012 * 013 * <br><br> 014 * 015 * @version 016 * StudentSct 1.1 (Student Sectioning)<br> 017 * Copyright (C) 2007 Tomáš Müller<br> 018 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 019 * Lazenska 391, 76314 Zlin, Czech Republic<br> 020 * <br> 021 * This library is free software; you can redistribute it and/or 022 * modify it under the terms of the GNU Lesser General Public 023 * License as published by the Free Software Foundation; either 024 * version 2.1 of the License, or (at your option) any later version. 025 * <br><br> 026 * This library is distributed in the hope that it will be useful, 027 * but WITHOUT ANY WARRANTY; without even the implied warranty of 028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 029 * Lesser General Public License for more details. 030 * <br><br> 031 * You should have received a copy of the GNU Lesser General Public 032 * License along with this library; if not, write to the Free Software 033 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 034 */ 035 public class Config { 036 private long iId = -1; 037 private String iName = null; 038 private Offering iOffering = null; 039 private Vector iSubparts = new Vector(); 040 041 /** Constructor 042 * @param id instructional offering configuration unique id 043 * @param name configuration name 044 * @param offering instructional offering to which this configuration belongs 045 */ 046 public Config(long id, String name, Offering offering) { 047 iId = id; 048 iName = name; 049 iOffering = offering; 050 iOffering.getConfigs().add(this); 051 } 052 053 /** Configuration id */ 054 public long getId() { 055 return iId; 056 } 057 058 /** Configuration name */ 059 public String getName() { 060 return iName; 061 } 062 063 /** Instructional offering to which this configuration belongs. */ 064 public Offering getOffering() { 065 return iOffering; 066 } 067 068 /** List of subparts */ 069 public Vector getSubparts() { 070 return iSubparts; 071 } 072 073 public String toString() { 074 return getName(); 075 } 076 077 /** Average minimal penalty from {@link Subpart#getMinPenalty()} */ 078 public double getMinPenalty() { 079 double min = 0.0; 080 for (Enumeration e=getSubparts().elements();e.hasMoreElements();) { 081 Subpart subpart = (Subpart)e.nextElement(); 082 min += subpart.getMinPenalty(); 083 } 084 return min / getSubparts().size(); 085 } 086 087 /** Average maximal penalty from {@link Subpart#getMaxPenalty()} */ 088 public double getMaxPenalty() { 089 double max = 0.0; 090 for (Enumeration e=getSubparts().elements();e.hasMoreElements();) { 091 Subpart subpart = (Subpart)e.nextElement(); 092 max += subpart.getMinPenalty(); 093 } 094 return max / getSubparts().size(); 095 } 096 }