Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nego cheat #579

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions airline-data/src/main/scala/com/patson/model/Link.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ case class Link(from : Airport, to : Airport, airline: Airline, price : LinkClas
futureCapacity
}

/**
* Future LinkValues based on configuration that can accommodate the max pax (ie single class configuration with lowest space multiplier).
*
* This is usually only used for negotiation calculations
* @return
*/
def futureMaxCapacity(): LinkClassValues = {
//need to do all these calculations so we an support class with a non 1 lowest space multiplier...
val lowestClass = LinkClass.values.sortBy(_.spaceMultiplier).head
var maxCapacity = LinkClassValues.getInstance()
assignedAirplanes.foreach {
case (airplane, assignment) => {
val maxCapacityPerFlight = LinkClassValues.getInstanceByMap(Map(lowestClass -> (airplane.model.capacity / lowestClass.spaceMultiplier).toInt))
//not doing maxCapacityPerFlight * futureFrequency ...in case we allow mixed model in the future...
maxCapacity = maxCapacity + (maxCapacityPerFlight * assignment.frequency)
}
}

maxCapacity
}

def futureFrequency() = {
assignedAirplanes.values.map(_.frequency).sum
}
Expand Down
12 changes: 9 additions & 3 deletions airline-web/app/controllers/NegotiationUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ object NegotiationUtil {
val officeStaffCount : Int = baseOption.map(_.getOfficeStaffCapacity).getOrElse(0)
val airlineLinksFromThisAirport = airlineLinks.filter(link => link.from.id == airport.id && (isNewLink || link.id != existingLinkOption.get.id))
val currentOfficeStaffUsed = airlineLinksFromThisAirport.map(_.getFutureOfficeStaffRequired).sum
val newOfficeStaffRequired = newLink.getFutureOfficeStaffRequired
/**
* Use futureMaxCapacity for calculating negotiation difficulty to avoid loophole of negotiating with first class and switch config
*/
val newOfficeStaffRequired : Int = {
newLink.getOfficeStaffRequired(newLink.from, newLink.to, newLink.futureFrequency(), newLink.futureMaxCapacity())
}
val newTotal = currentOfficeStaffUsed + newOfficeStaffRequired

if (newTotal < officeStaffCount) {
Expand Down Expand Up @@ -154,10 +159,11 @@ object NegotiationUtil {
case class FrequencyRestrictionByModel(threshold : Int, frequencyRestriction : Int)

def getToAirportRequirements(airline : Airline, newLink : Link, existingLinkOption : Option[Link], airlineLinks : List[Link]) = {
val newCapacity : LinkClassValues = newLink.futureCapacity()
//use futureMaxCapacity as calculation, to avoid cheat of changing config after negotiation
val newCapacity = newLink.futureMaxCapacity()
val newFrequency = newLink.futureFrequency()

val existingCapacity = existingLinkOption.map(_.futureCapacity()).getOrElse(LinkClassValues.getInstance())
val existingCapacity = existingLinkOption.map(_.futureMaxCapacity()).getOrElse(LinkClassValues.getInstance())
val existingFrequency = existingLinkOption.map(_.futureFrequency()).getOrElse(0)

val capacityDelta = normalizedCapacity(newCapacity - existingCapacity)
Expand Down