JSprit: How to maximize the number of available vehicles to reduce time - java

I am trying to solve a vrp which consists of pickups and deliveries. I have 73 vehicles and I want to use all the available vehicles to reduce overall time of process. I observed that the result is 24 vehicles never been used while other got multiple jobs. The issue is some of assigned vehicle actually come back to the next job at location that is nearer to unassigned vehicle while further to it last location. So looks like the engine still trying to use least vehicle. How could I change the parameters like:
“FixedCost”,
“DistanceCost”,
“TravelTimeCost”,
“WaitingTimeCost”
to maximize the number of vehicles used? I have tried to change some ways (put some values to FixedCost or make it equal to zero), add values to DistanceCost, TravelTimeCost, but still not working. I still seeing vehicles taking multiple jobs while many vehicle nearer to some of that jobs will never been used on it's available time.

I believe maximizing number of vehicles is not your genuine demand but maybe you want to minimize the longest route in terms of time.
So that is the same problem as AbeProblemMinMax.
However, this is implemented in jsprit v1.3 which is a quite old version. See here for a re-implementation in v1.7.3.

Related

Automatically running AnyLogic sliders so that different combinations are chosen

I am creating a system dynamics model in AnyLogic to be representative of a water mass balance for a city. One of the important aspects of this is to understand how different conservation measures affect supply-demand relationships. There are 3 different conservation measures and there are five different levels of adoption for each: 0%, 25%, 50%, 75%, and 100%. This makes a total of 125 combinations. I was thinking of linking the 3 parameters to sliders in order to choose the level of adoption, but going through each combination manually appears to be unnecessarily grueling. Does anyone know if it is possible that during run time the model is able to choose the different combinations on its own? If so, how can this be accomplished?
Parameter variation experiment should be ideal for what you need: https://anylogic.help/anylogic/experiments/parameter-variation.html#parameter-variation-experiment
Create a parameter in main for each measure you want to vary. Then, in the experiment's properties, you can specify the range and step to define the different values you want the parameters to take.
Then, when you run it, all possible combinations will be run.

Dynamically group clients by location, limited to a maximum size

So I am working on a project that requires a collection of clients to be iterated through for updating, with each client requiring an update packet for every other client within proximity. I want to be able to do this in a fast way since updates will happen for a large amount of clients, at an often-occurring interval.
My original plan of attack was to create regions based on client locations, updating each client only with the other clients in their region. This would entail a LinkedList<Region>, with the Region having its own list of clients which would update among each other. One problem with this method was that some regions could have 1 client, while others could have 1000. Another level of difficulty arose from the fact that clients will constantly be moving (thus changing location and Region). These problems could be avoided if there was a way to modify the list while iterating through it, possibly splitting elements when a region gets too large.
Next I thought of creating one large List<Client> that held all players, which was constantly sorted based on location. Then to update client at index n of the list with the closest 20 clients, I would only iterate n-10 and n+10 from their current index. I don't really like this method as much since if there was a 21st client in a closeby area, they could be ignored even though they had equal distance to the client at n as the one at n+10. It also seemed slow to have to resort all the clients every tick.
In terms of speed, which of these methods provides better performance? Additionally, are there any other Java collections I should consider? Thanks!
I strongly prefer the first method. Sorting the entire list every tick is going to end up being a very bad idea time-wise, which rules out the second method.
To solve the concurrency issues, you should make a copy of the LinkedList<Reigon> before updating it in a thread. That way you will allow Clients to change their Reigon at the same time as updates are being pushed out to each Reigon.
Another note is that if you plan on retrieving an arbitrary Reigon from the LinkedList<Reigon> (for example, when you move a Client from one Reigon to another) you should look into some kind of a hash set. It will increase performance greatly when retrieving an arbitrary element from the middle of the list, especially if the list is large.

How can I implement a dynamic selection?

I am making a strategy game AI. Specifically, I'm using BWMirror java library to make Starcraft: BroodWar zerg AI.
I came accross a problem with unit management. Player has some units in his disposition, let's say it's List<Unit> with such contents:
Offset Name Position
0. Drone [Worker]
1. Drone [Worker]
2. Zergling [Fighter]
3. Hatchery [Building]
4. Drone [Worker]
5. Larva [Passive]
Some functions obviously only work with unit subsets. I have implemented a method that selects subset from the main list and returns it as new list. For workers, I'd get:
Offset Name Position
0. Drone [Worker]
1. Drone [Worker]
2. Drone [Worker]
Now if one of these workers is removed from the original list (eg. because it dies), it will persist in this sub-list. There are 2 possible solutions and I don't like either:
Generate the selection list every time when needed.
Assign some event callbacks to remove items in all lists they are present in.
My questions is: Is there any kind of data storage that would let me make sub-selections but allow me to keep the data synchronized?
This means I'd have two Iterable objects and one would contain all units, other would contain workers. And removing worker from all units would also make it disappear from workers, without any callback.
I think you only have the 2 options you listed, and of the two, I think your first option makes the most sense.
Lazily generating the list only when you needed it would save a lot of cycles. One stim packed up Marine (such as yourself) , might kill a huge number of zerglings, you really don't want to be sending messages for every zergling that dies. It would be much better to just see what you have left when you need them.

R-Tree implementation in Java [duplicate]

I was searching the last few days for a stable implementation of the R-Tree with support of unlimited dimensions (20 or so would be enough). I only found this http://sourceforge.net/projects/jsi/ but they only support 2 dimensions.
Another Option would be a multidimensional implementation of an interval-tree.
Maybe I'm completly wrong with the idea of using an R-Tree or Intervall-Tree for my Problem so i state the Problem in short, that you can send me your thoughts about this.
The Problem I need to solve is some kind of nearest-neighbour search. I have a set of Antennas and rooms and for each antenna an interval of Integers. E.g. antenna 1, min -92, max -85. In fact it could be represented as room -> set of antennas -> interval for antenna.
The idea was that each room spans a box in the R-Tree over the dimension of the antennas and in each dimension by the interval.
If I get a query with N-Antennas and values for each antenna I then could just represent the Information as a query point in the room and retrieve the rooms "nearest" to the point.
Hope you got an Idea of the problem and my idea.
Be aware that R-Trees can degrade badly when you have discrete data. The first thing you really need to find out is an appropriate data representation, then test if your queries work on a subset of the data.
R-Trees will only make your queries faster. If they don't work in the first place, it will not help. You should test your approach without using R-Trees first. Unless you hit a large amount of data (say, 100.000 objects), a linear scan in-memory can easily outperform an R-Tree, in particular when you need some adapter layer because it is not well-intergrated with your code.
The obvious approach here is to just use bounding rectangles, and linearly scan over them. If they work, you can then store the MBRs in an R-Tree to get some performance improvements. But if it doesn't work with a linear scan, it won't work with an R-Tree either (it will not work faster.)
I'm not entirely clear on what your exact problem is, but an R-Tree or interval tree would not work well in 20 dimensions. That's not a huge number of dimensions, but it is large enough for the curse of dimensionality to begin showing up.
To see what I mean, consider just trying to look at all of the neighbors of a box, including ones off of corners and edges. With 20 dimensions, you'll have 320 - 1 or 3,486,784,400 neighboring boxes. (You get that by realizing that along each axis a neighbor can be -1 unit, 0 unit, or +1 unit, but (0,0,0) is not a neighbor because it represents the original box.)
I'm sorry, but you either need to accept brute force searching, or else analyze your problem better and come up with a cleverer solution.
I have found this R*-Tree implementation in Java which seems to offer many features:
https://github.com/davidmoten/rtree
You might want to check it out!
Another good implementation in Java is ELKI: https://elki-project.github.io/.
You can use PostgreSQL’s Generalized Search Tree indexing facility.
GiST
Quick demo

Appropriate datastructure or implementation class for holding a small but changing collection

I have written following game server and want to provide a groups feature. Groups will allow to group players together who are "nearby" on screen. In fast action games, this group would be changing fast since players will be moving in and out of their zones constantly.
Since each player would need to listen to events from other players in the group, players will subscribe to the group.
This brings me to my question. What is the appropriate datastructure or java collection class which can be used in this scenario to hold the changing set of event listeners on a group? The number of listeners to a group would rarely exceed 20 in my opinion, and should be lesser than that in most scenarios. It is a multi-threaded environment.
The one I am planning to use is a CopyOnWriteArrayList. But since there will be reasonable amount of updates(due to changing subscriptions) is this class appropriate? What other class would be good to use? If you have any custom implementation using array's etc please share.
Unless you have millions of changes per second (which seems unlikely in your scenario) a CopyOnWriteArrayList should be good enough for what you need. If I were you, I would use that.
IF you notice a performance issue AND you have profiled your application AND you have identified that the CopyOnWriteArrayList is the bottleneck, then you can find a better structure. But I doubt it will be the case.
Do players have integer IDs? If so then I have an lightweight, immutable array-based set class that might make sense for you:
http://code.google.com/p/mikeralib/source/browse/trunk/Mikera/src/main/java/mikera/persistent/IntSet.java
This was written for similar kinds of situations in game engines.
However I also have an alternative approach to consider: If you are updating the groups automatically based on vicinity, then you might want to consider not tracking groups at all. Instead, consider using a spatial data structure that allows you to quickly search for nearby players whenever an event occurs, and directly send the event to nearby players.
Typically you could use a 2D or 3D grid or octree with the smallest division size set to be equal to the max range for your groups. Then a vicinity search will only need to check 9 (2D case) or 27 (3D case) locations in order to find all nearby players. I think doing this search whenever needed will be faster and simpler than the overhead of maintaining lists of groups and listeners all the time....
From what I've gathered, you have choice between CopyOnWriteArrayList and ConcurrentHashMap:
CopyOnWriteArrayList:
Add/remove operation computational cost is linear to the size of the list. May happen multiple times during a single iteration (group notification).
Simpler data structure with constant read time.
ConcurrentHashMap:
Add/remove operation is a constant time operation. Additions or Removal of subscribers do not affect iteration already in progress and blocking is minimized.
Larger data structure that requires slightly longer read time.
Creating a custom solution is possible when it comes to efficiency but probably not as safe when it comes to thread safety. I'm leaning towards ConcurrentHashMap but the winner will probably depend heavily on how your game turns out.

Categories

Resources