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

SkimPlus & RepositioningManager #1585

Merged
merged 33 commits into from
May 24, 2019
Merged

SkimPlus & RepositioningManager #1585

merged 33 commits into from
May 24, 2019

Conversation

haitamlaarabi
Copy link
Collaborator

@haitamlaarabi haitamlaarabi commented Mar 28, 2019

new skim data structure that should include additional information associated to every TAZ, such available vehicles by VehicleManager

Closes #1540


This change is Reviewable

@ghost ghost assigned haitamlaarabi Mar 28, 2019
@ghost ghost added the Review label Mar 28, 2019
@haitamlaarabi
Copy link
Collaborator Author

test!

@haitamlaarabi
Copy link
Collaborator Author

test!

Copy link
Collaborator

@JustinPihony JustinPihony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor formatting item to take or leave :)

src/main/scala/beam/router/BeamSkimmer.scala Outdated Show resolved Hide resolved
@haitamlaarabi haitamlaarabi changed the title SkimPlus added to BeamSkimmer SkimPlus & RepositioningManager Apr 5, 2019
@haitamlaarabi
Copy link
Collaborator Author

test!

@haitamlaarabi
Copy link
Collaborator Author

test!

@ghost ghost assigned JustinPihony Apr 16, 2019
@JustinPihony
Copy link
Collaborator

test!

@JustinPihony
Copy link
Collaborator

Is this still wanted. It went stale, so I'm not sure. If it is then I can fix the current compiler errors

Copy link
Collaborator

@JustinPihony JustinPihony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be pointing to master or dev? It seems like a heavy one to go straight to master

@@ -190,6 +196,16 @@ class BeamSkimmer @Inject()(val beamConfig: BeamConfig, val beamServices: BeamSe
}
}

def getPreviousSkimValueOrDefault(time: Int, mode: BeamMode, orig: Id[TAZ], dest: Id[TAZ]): Skim = {
previousSkims.get((timeToBin(time), mode, orig, dest)) match {
case someSkim @ Some(_) => someSkim.get.toSkimExternal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be rewritten like case Some(skim) => skim.toSkimExternal

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

label: Label,
who: Option[Id[Person]]
): Unit = {
who match {
Copy link
Collaborator

@REASY REASY May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just need to do some side-effect on who in case it is Some, you could use foreach:

who.foreach { _ =>
        val timeBin = timeToBin(time, timeWindow)
        val taz = beamServices.tazTreeMap.getTAZ(location.getX, location.getY)
        val key = (timeBin, taz.tazId, vehicleManager, label)
        skimsPlus.put(key, skimsPlus.getOrElse(key, 1.0) + 1.0)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I already removed the who from the parameters. I realized afterwards that I don't need it.

var destTimeOpt: Option[(RepositioningRequest, Int)] = None
undersuppliedTAZ.foreach { dst =>
val skim = beamSkimmer.getPreviousSkimValueOrDefault(startTime, BeamMode.CAR, org.taz.tazId, dst.taz.tazId)
if (destTimeOpt.isEmpty || (destTimeOpt.isDefined && skim.time < destTimeOpt.get._2)) {
Copy link
Collaborator

@REASY REASY May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be rewritten like, but not sure that it looks better :D

destTimeOpt match {
  case None =>
    destTimeOpt = Some((dst, skim.time))
  case Some((_, time)) if skim.time < time =>
    destTimeOpt = Some((dst, skim.time))
  case _ =>
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case I prefer the "if" since there are less line of codes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as an FYI, I don't think you gain much in allocation in the current mutable state, so maybe a foldLeft would be better overall?

	oversuppliedTAZ.foreach{ org => 
	  undersuppliedTAZ.foldLeft(None: Option[(RepositioningRequest, Int)]){ case (destTimeOpt, dst) =>
	    val skim = beamSkimmer.getPreviousSkimValueOrDefault(startTime, BeamMode.CAR, org.taz.tazId, dst.taz.tazId)
		if(destTimeOpt.isEmpty) Some(dst, skim.time)
		else destTimeOpt.collect{ case destTime if skim.time > destTime._2 => Some((dst,skim.time))}.getOrElse(destTimeOpt)
	  }.foreach{ case (dst, time) => ODs.append((org, dst, time))}
	}

destTimeOpt = Some((dst, skim.time))
}
}
destTimeOpt match {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If just side-effect should happen, also could use destTimeOpt.foreach

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

log.debug("Checked out " + token.id)
case _ =>
who ! NotAvailable
println(s"to board ===> ${token.id}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is preferable to use logger.debug and adjust debug level for particular class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already removed all these println lines

RepositionManagerListener.writeRepositionEvents(event, eventsList)
}

val eventsList = mutable.ListBuffer.empty[(Int, Id[TAZ], Id[VehicleManager], Id[BeamVehicle], String, String)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many events will be here? Could it cause an issue (memory) on production run with a lot of vehicles? If it is stored only for the purpose of writing it in the end of iteration, it can be written during the simulation instead of accumulating all events

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is the big change I did since yesterday. I got rid of the whole listener thing and rather used the skimmer with more or less same purpose

managerType = "fixed_non_reserving_fleet_from_file"
fixed_non_reserving_fleet_from_file {
vehicleTypeId = "PHEV",
filename = "/Users/haitam/workspace/beam/test/input/beamville/vehiclesShared.csv"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, make sure this path exist everywhere (maybe need to add it under sourcecontrol)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad didn't plan to push the conf file

beam.warmStart.enabled = false
beam.warmStart.path = "https://s3.us-east-2.amazonaws.com/beam-outputs/run149-base__2018-06-27_20-28-26_2a2e2bd3.zip"
beam.warmStart.enabled = true
beam.warmStart.path = "/Users/haitam/workspace/beam/output/beamville/beamville__2019-05-13_17-18-48/ITERS/it.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, make sure this path exist everywhere (maybe need to add it under sourcecontrol)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

mutable.TreeSet.empty[RepositioningRequest](Ordering.by[RepositioningRequest, Int](_.shortage))

beamServices.tazTreeMap.getTAZs.foreach { taz =>
if (relocate) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing happens in the loop if relocate is false, so it can be taken out of loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I changed this code too

@JustinPihony JustinPihony changed the base branch from master to develop May 22, 2019 17:33
@JustinPihony JustinPihony dismissed their stale review May 22, 2019 17:34

Changed to develop

@michaz
Copy link
Collaborator

michaz commented May 23, 2019

test!

@michaz michaz merged commit 2387922 into develop May 24, 2019
@michaz michaz deleted the HL/#1540-rebalancing-bis branch May 24, 2019 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rebalancing
4 participants