scheduler.fair_qual
Class Fair_Qual

java.lang.Object
  extended by scheduler.fair_qual.Fair_Qual
All Implemented Interfaces:
java.util.Observer

public class Fair_Qual
extends java.lang.Object
implements java.util.Observer

Fair_Qual contains methods to judge a schedule against preferences and determine the Fairness and Quality of the given schedule.

Author:
Alex Lindt (alindt@calpoly.edu)

Field Summary
private  int current_index
          The index being looked at by FairUI
private  float f_avg
          Average fairness value.
private  double f_dev
          Standard deviation of fairness values
private  int f_high
          Highest fairness value
private  int f_low
          Lowest fairness value
private  java.util.ArrayList<java.lang.Integer> fairness
          Holds fairness values for the instructors in instructor_list
private  java.util.ArrayList<java.lang.Integer> hits
          Holds the number of assigned classes and times for a given isntructor
private  java.util.ArrayList<Instructor> instructor_list
          Contains all instructor's who have a fairness value computed
private  java.util.ArrayList<java.lang.Integer> quality
          Holds quality values for the instructors in instructor_list
private  Schedule schedule
          Each instructor's schedule
 
Constructor Summary
Fair_Qual()
          Sets all variables and attempts to fill instructor_list with the current schedule (if any).
Fair_Qual(Schedule cur_schedule)
          Sets all variables and sets canned data for testing purposes
 
Method Summary
private  double calculateDeviation()
          calculates standard deviation
 void clearLists()
          Helper function to empty all current lists
private  void generateFairness()
          Calculates the fairness and associated statistics (avg,low,high,etc) for all instructors with a generated schedule.
private  void generateFairnessStats()
          generates associated statistics for overall data, such as highest, lowest, or average fairness.
 void generateQuality()
          generateQuality will calculate the fairness and associated statistics (avg,low,high,etc) for all instructors with a generated schedule.
 float getAvg()
          returns the average fairness value
 int getCurrentFairness()
          returns the fairness value at the current_index
 Instructor getCurrentInstructor()
          returns the instructor at the current_index
 int getCurrentQuality()
          returns the quality value at the current_index
 double getDev()
          returns the standard deviation of stored fairness values
 int getFairness(int index)
          returns the fairness value at a given index
static int getGenerosity(Instructor inst, java.util.LinkedList<Course> courses)
          Takes in an isntructor and sums up the values of all of their course and time preferences.
 int getHigh()
          returns the highest fairness value
 int getIndex()
          returns the current index being viewed by the UI
 Instructor getInstructor(int index)
          returns the instructor at a given index
 int getLow()
          returns the lowest fairness value
 double getLowerBound()
          Calculates lower bound, any fairness value lower than the lower bound is statistically considered to be an outlier.
 int getQuality(int index)
          returns the quality value at a given index
 Schedule getSchedule()
          returns the schedule
 java.util.ArrayList<java.lang.Integer> getScheduleItemIndices(int index)
          returns all the instructor's schedule item indices
 int getSize()
          returns the number of instructor's stored
 double getUpperBound()
          Calculates upper bound, any fairness value higher than the upper bound is statistically considered to be an outlier.
private  void initSettings()
          Variable declarations
 boolean setFairness(Instructor instructor, int new_fairness)
          setFairness will modify the fairness value of a given schedule and set it to the new_fairness value.
 boolean setIndex(int index)
          sets the index being viewed by the UI
 boolean setQuality(Instructor instructor, int new_quality)
          setQuality will modify the quality value of a given schedule and set it to the new_quality value.
 void update(java.util.Observable obs, java.lang.Object obj)
          Updates the lists when it's observable targets change
private  void updateLists()
          Synchronizes lists with the updated schedule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instructor_list

private java.util.ArrayList<Instructor> instructor_list
Contains all instructor's who have a fairness value computed


fairness

private java.util.ArrayList<java.lang.Integer> fairness
Holds fairness values for the instructors in instructor_list


quality

private java.util.ArrayList<java.lang.Integer> quality
Holds quality values for the instructors in instructor_list


hits

private java.util.ArrayList<java.lang.Integer> hits
Holds the number of assigned classes and times for a given isntructor


f_avg

private float f_avg
Average fairness value.


f_dev

private double f_dev
Standard deviation of fairness values


f_low

private int f_low
Lowest fairness value


f_high

private int f_high
Highest fairness value


current_index

private int current_index
The index being looked at by FairUI


schedule

private Schedule schedule
Each instructor's schedule

Constructor Detail

Fair_Qual

public Fair_Qual()
Sets all variables and attempts to fill instructor_list with the current schedule (if any).


Fair_Qual

public Fair_Qual(Schedule cur_schedule)
Sets all variables and sets canned data for testing purposes

Parameters:
cur_schedule - current list of all generated schedules
Method Detail

initSettings

private void initSettings()
Variable declarations


update

public void update(java.util.Observable obs,
                   java.lang.Object obj)
Updates the lists when it's observable targets change

Specified by:
update in interface java.util.Observer
Parameters:
obs - Object observed
obj - I don't know

updateLists

private void updateLists()
Synchronizes lists with the updated schedule


generateFairness

private void generateFairness()
Calculates the fairness and associated statistics (avg,low,high,etc) for all instructors with a generated schedule.

"fairness_value" represents the fairness, and has a range from 1-10. a fairness_value of 1 means the schedule for the schedule is most fair, while 10 is the least fair.

pre: schedule.getInstructorList().size() >= 0

post: forall(stored_schedules) stored_schedules[i].instructor.fairness = sum(10 - each time/course preference assigned in instructor's schedule) / (total assignments)


generateFairnessStats

private void generateFairnessStats()
generates associated statistics for overall data, such as highest, lowest, or average fairness. Other statistics are computed ass well.


calculateDeviation

private double calculateDeviation()
calculates standard deviation

pre: fairness.size() > 1

post: dev = standardDeviation(ofAllStoredFairnessValues)

Returns:
dev the standard deviation

generateQuality

public void generateQuality()
generateQuality will calculate the fairness and associated statistics (avg,low,high,etc) for all instructors with a generated schedule.

"quality_value" represents the quality, and has a range from 1-10. a quality_value of 1 means the schedule for the schedule is of the most quality, while 10 is the least quality.

pre: schedule.getInstructorList().size()

post: forall(stored_schedules) stored_schedules[i].instructor.quality = (1 / (sum of all quality violations))*10


setFairness

public boolean setFairness(Instructor instructor,
                           int new_fairness)
                    throws Instructor.NullUserIDException
setFairness will modify the fairness value of a given schedule and set it to the new_fairness value. The function will return true if the fairness value is successfully set.

pre: (to_modify != NULL) && (new_fairness > 0 && new_fairness < 11)

post: return (to_modify.fairness = new_fairness)

Parameters:
to_modify - the schedule being modified.
new_fairness - the value to set the fairness as.
Returns:
true if to_modify.fairness is successfully changed. false if otherwise
Throws:
Instructor.NullUserIDException

setQuality

public boolean setQuality(Instructor instructor,
                          int new_quality)
                   throws Instructor.NullUserIDException
setQuality will modify the quality value of a given schedule and set it to the new_quality value. The function will return true if the quality value is successfully set.

pre: (to_modify != NULL) && (new_quality > 0 && new_quality < 11)

post: return (to_modify.quality = new_quality)

Parameters:
to_modify - the schedule being modified.
new_ - quality the value to set the quality as.
Returns:
true if to_modify.quality is successfully changed. false if otherwise
Throws:
Instructor.NullUserIDException

getGenerosity

public static int getGenerosity(Instructor inst,
                                java.util.LinkedList<Course> courses)
Takes in an isntructor and sums up the values of all of their course and time preferences. That value represents that professor's Generosity, where higher values mean the professor was less generous, while lower values mean the professor was more generous.

pre: inst != null;

post: forall(preferences) { generosity += preference.desire; }

Parameters:
inst - the instructor to determine generosity for
courses - classes with specified preferences
Returns:
the sum of all (time/class).desire()

getScheduleItemIndices

public java.util.ArrayList<java.lang.Integer> getScheduleItemIndices(int index)
returns all the instructor's schedule item indices


getAvg

public float getAvg()
returns the average fairness value


getLow

public int getLow()
returns the lowest fairness value


getHigh

public int getHigh()
returns the highest fairness value


getIndex

public int getIndex()
returns the current index being viewed by the UI


getSize

public int getSize()
returns the number of instructor's stored


setIndex

public boolean setIndex(int index)
sets the index being viewed by the UI


getInstructor

public Instructor getInstructor(int index)
returns the instructor at a given index


getCurrentInstructor

public Instructor getCurrentInstructor()
returns the instructor at the current_index


getFairness

public int getFairness(int index)
returns the fairness value at a given index


getCurrentFairness

public int getCurrentFairness()
returns the fairness value at the current_index


getQuality

public int getQuality(int index)
returns the quality value at a given index


getCurrentQuality

public int getCurrentQuality()
returns the quality value at the current_index


getSchedule

public Schedule getSchedule()
returns the schedule


getDev

public double getDev()
returns the standard deviation of stored fairness values


getUpperBound

public double getUpperBound()
Calculates upper bound, any fairness value higher than the upper bound is statistically considered to be an outlier.

Returns:
Upper_bound average + 2*std_deviation

getLowerBound

public double getLowerBound()
Calculates lower bound, any fairness value lower than the lower bound is statistically considered to be an outlier.

Returns:
Lower_bound average - 2*std_deviation

clearLists

public void clearLists()
Helper function to empty all current lists