What is the correct way to add different objects (Parcel) at the same position? - rinsim

I'm trying to add diferent Parcel objects at the same position. My code looks like this, where Rock extends Parcel:
Point origin = null;
Rock rock = null;
for (int i = 0; i < ROCKS; i++) {
if (i % 10 == 0) {
origin = model.getRandomUnoccupiedPosition(sim.getRandomGenerator());
rock = new Rock(origin, destination);
sim.register(rock);
} else {
Rock r = new Rock(origin, destination);
model.addObjectAtSamePosition(r, rock);
}
}
but after a few iterations, I get this error when trying to pick up the Rock with a Vehicle:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: Parcel must be registered and must be either ANNOUNCED or AVAILABE, it is: null. Parcel: [Parcel-103f852].
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:146)
at com.github.rinde.rinsim.core.model.pdp.DefaultPDPModel.pickup(DefaultPDPModel.java:175)
at me.alexrs.mas.roveragent.RoverAgent.tickImpl(RoverAgent.java:105)
at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:399)
The only Rock that is registered is the one that has been registered in the Simulator, but if I try to register more than one Rock, I get an exception saying that two objects can't be at the same position.

Related

Can't access GLTF/GLB submesh nor material info when using (archived) Sceneform 1.16.0

Under Sceneform 1.16.0 is not possible to access to submeshes nor materials info present in a GLTF/GLB file, as their count is always zero.
Regarding that this is now an open-source (and archived-abandoned) project by Google, it's possible to inspect the code of Renderable class in order to try to locate where the problem is generated.
This brings us to the constructor:
#SuppressWarnings("initialization")
protected Renderable(Renderable other) {
if (other.getId().isEmpty()) {
throw new AssertionError("Cannot copy uninitialized Renderable.");
}
// Share renderableData with the original Renderable.
renderableData = other.renderableData;
// Copy materials.
Preconditions.checkState(other.materialNames.size() == other.materialBindings.size());
for (int i = 0; i < other.materialBindings.size(); i++) {
Material otherMaterial = other.materialBindings.get(i);
materialBindings.add(otherMaterial.makeCopy());
materialNames.add(other.materialNames.get(i));
}
renderPriority = other.renderPriority;
isShadowCaster = other.isShadowCaster;
isShadowReceiver = other.isShadowReceiver;
// Copy collision shape.
if (other.collisionShape != null) {
collisionShape = other.collisionShape.makeCopy();
}
changeId.update();
}
...where the original Renderable (other) has zero submeshes (other.renderableData) and materials (other.materialBindings).
Any help with this?
Best regards.

Updating a point in a line chart when data grouping is in effect

I need to update a specific point in the chart when new data arrives. I've written the following function:
function updatePoint(series, x, y) {
for (i = 0; i < series.data.length - 1; i++) {
var point = series.data[i];
if (point.x === x) {
point.update(y);
return;
}
}
}
This works fine, unless the chart has more than turboThreshold points, in which case the series.data is gone, and I only have series.xData and series.yData to work with. I tried the following variant, but the chart does not actually update:
function updateTurboPoint(series, x, y) {
for (i = 0; i < series.xData.length; i++) {
if (series.xData[i] === x) {
if (series.yData.length > i) {
series.yData[i] = y;
return;
}
}
}
}
Setting a breakpoint on the return, I verified that series.yData[i] has the new value, even though it did not appear on the chart. How can I get this to actually update the chart?
I am using HighStock 2.0.4.
EDIT: Created a JSFiddle: http://jsfiddle.net/swish014/2unh1cLa/
EDIT: Changed the title, as I (now) do not believe turbo mode has anything to do with it.
The two comments were key to figuring out my own problem.
It is related to dataGrouping (and not turbo mode as I first thought).
The series.points array does exist, and updating a point there does update the chart as desired.
In my question, I listed two separate functions to update points, but I believe I can use just one function:
function updatePoint(series, x, y) {
for (i = 0; i < series.points.length - 1; i++) {
var point = series.points[i];
if (point.x === x) {
point.update(y);
return;
}
}
}

Looking for speedups for A* search

I've got the following working A* code in C#:
static bool AStar(
IGraphNode start,
Func<IGraphNode, bool> check,
out List<IGraphNode> path)
{
// Closed list. Hashset because O(1).
var closed =
new HashSet<IGraphNode>();
// Binary heap which accepts multiple equivalent items.
var frontier =
new MultiHeap<IGraphNode>(
(a, b) =>
{ return Math.Sign(a.TotalDistance - b.TotalDistance); }
);
// Some way to know how many multiple equivalent items there are.
var references =
new Dictionary<IGraphNode, int>();
// Some way to know which parent a graph node has.
var parents =
new Dictionary<IGraphNode, IGraphNode>();
// One new graph node in the frontier,
frontier.Insert(start);
// Count the reference.
references[start] = 1;
IGraphNode current = start;
do
{
do
{
frontier.Get(out current);
// If it's in the closed list or
// there's other instances of it in the frontier,
// and there's still nodes left in the frontier,
// then that's not the best node.
} while (
(closed.Contains(current) ||
(--references[current]) > 0) &&
frontier.Count > 0
);
// If we have run out of options,
if (closed.Contains(current) && frontier.Count == 0)
{
// then there's no path.
path = null;
return false;
}
closed.Add(current);
foreach (var edge in current.Edges)
{
// If there's a chance of a better path
// to this node,
if (!closed.Contains(edge.End))
{
int count;
// If the frontier doesn't contain this node,
if (!references.TryGetValue(edge.End, out count) ||
count == 0)
{
// Initialize it and insert it.
edge.End.PathDistance =
current.PathDistance + edge.Distance;
edge.End.EstimatedDistance = CalcDistance(edge.End);
parents[edge.End] = current;
frontier.Insert(edge.End);
references[edge.End] = 1;
}
else
{
// If this path is better than the existing path,
if (current.PathDistance + edge.Distance <
edge.End.PathDistance)
{
// Use this path.
edge.End.PathDistance = current.PathDistance +
edge.Distance;
parents[edge.End] = current;
frontier.Insert(edge.End);
// Keeping track of multiples equivalent items.
++references[edge.End];
}
}
}
}
} while (!check(current) && frontier.Count > 0);
if (check(current))
{
path = new List<IGraphNode>();
path.Add(current);
while (current.PathDistance != 0)
{
current = parents[current];
path.Add(current);
}
path.Reverse();
return true;
}
// Yep, no path.
path = null;
return false;
}
How do I make it faster? No code samples, please; that's a challenge I've set myself.
Edit: To clarify, I'm looking for any advice, suggestions, links, etc. that apply to A* in general. The code is just an example. I asked for no code samples because they make it too easy to implement the technique(s) being described.
Thanks.
Have you looked at this page or this page yet? They have plenty of helpful optimization tips as well as some great information on A* in general.
Change to using a Random Meldable Queue for the heap structure. Since you wanted a programming challenge, I won't show you how I changed the recursive Meld method to not be recursive. That's the trick to getting speed out of that structure. More info in Gambin's paper "Randomized Meldable Priority Queues" (search on the web for that).

How to find forground application Unique ID/Name in Blackberry

I have problem in finding the current opened application name.
I used ApplicationManager class for getting the visible applications.
The application descriptors are showing the same name for all these apps Email,Messaging,Sms,call log.
They are displaying "net_rim_bb_messaging_app" for all the above apps.
I need to find a unique identifier/name for these applications(Email,messaging,sms,calllog) when they are opened.
I tried this for the past 3 days and can't find a solution.
Can you please let me know a solution for this?
ApplicationDescriptor [] appDis = manager.getVisibleApplications();
int currentForgroundAppID = manager.getForegroundProcessId();
for(int i=0;i<appIDs.length;i++)
{
if(appDis[i].getModuleName().equals("net_rim_bb_messaging_app"))
{
//print Messaging app in foreground...
}
}
the case with in the for loop above is true for every app in this list.
Email,
Text message
Call log...
But, I need to find a unique way to find the application that was opened.
Thanks In Adv,
Satish.k
following code can display current foregroundApplication name
ApplicationDescriptor[] mAppDes;
ApplicationManager appMan = ApplicationManager.getApplicationManager();
appMan.getForegroundProcessId();
mAppDes = appMan.getVisibleApplications();
for (int i = 0; i < mAppDes.length; i++) {
boolean isFG = appMan.getProcessId(mAppDes[i]) == appMan.getForegroundProcessId();
if(isFG)
{
System.out.println("This is your Foteground application Name"+mAppDes[i].getName());
}else{
System.out.println("This is your Background application Name"+mAppDes[i].getName());
}
}

Blackberry: Not able to get locations SDCard/Media Card as fileSystemRoot?

I want to openOrCreate database in SDcard / Media Card. When i run the application in device (BlackBerry Curve 8900), i find only one root i.e "system/" and running application in simulator (9500), i find three roots as shown in comment in code. I am getting error at;
_db = DatabaseFactory.openOrCreate(_uri);
(error: Method "toString" with signature "()Ljava/lang/String;" is not applicable on this object)
And i am not able to understand what is this error about.
Here is the code.
public void getValues() throws Exception
{
boolean sdCardPresent = false;
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements())
{
root = (String)e.nextElement();
System.out.println("Value of root::" +root); // value of root = "system/" when run in device and
// value of root = "store/" "SDCard/" "system/" when run in simulator
if(root.equalsIgnoreCase("system/"))
{
sdCardPresent = true;
}
}
System.out.println("--------------------getValues()----------------------------------");
URI _uri = URI.create(Global.DB_PATH + Global.DB_Main);
System.out.println("Valud of uri::" +_uri);
_db = DatabaseFactory.openOrCreate(_uri); //getting error here.
System.out.println("Valud of _db::" +_db);
_db.close();
I tried these three paths, getting output with "/store"(when run in simulator) but error with rest two paths.Even using "/store" in device is showing the same error.
Global.DB_PATH = "/MediaCard/databases/";
Global.DB_PATH = "/SDCard/databases/";
Global.DB_PATH = "/store/databases/";
Is there any way how to get SDCard/Media Card as root so that i can copy the database in there?
My guess is when you are running your app on a real device you have USB cable plugged in to the device. If this is the case, try to unplug the cable and rerun the app. You may use Dialog.inform() to quickly check what roots you get this time.
private ObjectListField getFileList() {
if (fileList == null) {
fileList = new ObjectListField();
String[] roots = new String[3];
Enumeration enum = FileSystemRegistry.listRoots();
int x = 0;
while (enum.hasMoreElements()) {
if (x < 3) {
roots[x] = enum.nextElement().toString();
}
x++;
}
enum = FileSystemRegistry.listRoots();
fileList.set((roots[2] != null) ? roots : new String[]{"system/", "SDCard/", "store/"});
}
return fileList;
}
Try this code.

Resources