How to use edge abilities in practice with Jaseci? - jaseci

In a jac code, I want to use an edge ability. Let's imagine we have the following graph;
I have defined the edge ability as follows;
edge road{
has distance;
has count;
can count_travelers with traveler entry{
count = ++count;
std.out("travels");
}
}
I want to increase count when walker traveler travers through the edge road. This is my walker init
walker init{
root{
spawn here walker::build_example;
take-->;
}
city{
spawn here walker::traveler;
take-->;
}
}
The the code executes flawlessly but count does not increase. What am I missing here?
In the bible it was mentioned that edge can have abilities, but couldn't find any example in bible or in any codelabs in jaseci github repository.

In the current version of Jaseci, edge abilities only execute when explicitly called. If with entry or with exit is applied to an edge ability its basically ignored. You can call it with something like -->.edge[0]::count_travelers though.

Related

Swift flood fill algorithm randomly stopping

Here is the raw code but I will explain it roughly:
func processTile(_ tile: Tile) {
// Add tile to pos list if valid, otherwise prune the
branch
if isBarrier(tile) || alreadyChecked(tile) {
return
} else {
posList.append(tile.pos)
}
depth++ ; if depth > maxDepth { return }
for neighborTile in neighbors(of: tilePos) {
processTile(neighborTile)
}
}
This is the main recursive function. Basically it checks if a tile is part of a room by being neither a barrier tile or already checked. If either one of those cases is true then the branch of the flood tree is pruned and ended. If the tile was valid and was added to the list then the depth is incremented with a check on it. Then the tile's neighbors are all checked with the same process.
For some reason the flood algorithm just stops randomly. I changed the code adding a print() in front of the returns to see why a branch just stops. This worked for all the correct pruning cases where it hits a barrier or already checked tile, but when it would just randomly stop and not check a tile it didn't even log anything.
The only thing I can think of is that Swift stops executing the functions after a certain level of recursion. If this is the case does anyone know what the maximum number of recursions is? And what a possible workaround would be. I'm thinking you would have to make a list of all the "edge" tiles of the flood, and a list of all the "interior" tiles of the flood. Then have a while loop running until there are no edge tiles which just expands the flood.

Roblox - creating a multistory maze

I am trying to create a multistory maze. I found it fairly easy to create the first level, then I realized I had no idea how to simply raise this first level up in order to create a second level beneath it.
Also, is there a way to 'fuse' all of these wall parts into one object and then raise this object up?
Edit: Much to my embarrassment, their is a way to fuse objects. The 'Union' tool is what I needed, but had no idea existed. I 'fused' (unioned) the various parts that made up my walls and joined them together into one big part. After that unioning, moving the entire maze upwards became quite easy.
I don't understand your problem but I think that you're making a 3D maze in roblox and you want the first level to go up and the second level to form below the level.
If the maze is NOT procedurally generated AND the maps are built by hand. Then you can make the script detect if the player won, and then raise the first level by either using tween or using loops (I'd recommend tween because loops and linear tweening does the same), and then make an effect that shows it forming (Transparency, parts coming back together, etc..).
I will show you the simplest example. But you can add whatever you want
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.5, Enum.TweenStyle.Linear, Enum.TweenDirection.Out) --Customize it to your liking
local levels = game.LevelStorageParent.LevelFolderOrModelHere:GetChildren()
local pos = workspace.Level1.Position --Change (Not the levels because we are not cloning this)
local levelYRaise = 10 --Put any number or just get bounding box for full raise
ts:Create(workspace.Level1, ti, {Position = Vector3.new(pos.X, pos.Y+levelYRaise, pos.Z):Play()
local newLevel = levels.Level2:Clone()
newLevel.Parent = workspace
newLevel.Pos = workspace.Level1.Position - Vector3.new(0, workspace.Level1.Size.Y, 0)
newLevel.Transparency = 1
ts:Create(newLevel, ti, {Transparency = 0}):Play()
Change the code to your liking and your hierarchy names and parenting

HERE API:Swift. Wierd behaviour : Loops in a route - Creating a route based on GPS trace creates loops. / passthrough waypoints

im trying to create a route that follows a gps trace i provide.
The gps trace is cleaned up and it has no loops in it and is in correct order.
I checked it with other services.
It has 1920 points.
You can find the trace here GPX Files
Sadly if i create a route based on provided sdk example (github) i get loops in my path.
I was hoping you could help me to solve following problems:
how do i avoid loops while creating route by using HERE ios Swift SDK
how do i set route options is such way to follow provided point array and not create a fastest or balanced route.
Since i could not find those functions in Ios sdk i used additional REST API to filter the route a bit to remove all points that were not matched correctly according to here maps... before drawing the route.. ie everything with low probability, warnings, big distance to the road... yet the result is still not good. Here is a cleaned up file.. the file is being created after the original was maped / run once through HERE Maps. In this file all points that have low confidence or produce warnings or have big distance to original points .. are removed. This is the one i use to create a route and it still have the same issues like loops and weird turns.
Thank you very much in advance!
BR.
So far i have this code:
private lazy var router = NMACoreRouter()
#objc func do_routing_stuff( gps_trace :[NMAWaypoint]) {
var stops = [Any]()
stops = gps_trace
let routingMode = NMARoutingMode(routingType: .fastest,
transportMode: .car,
routingOptions: .avoidHighway)
// Trigger the route calculation
router.calculateRoute(withStops: stops ,
routingMode: routingMode)
{ [weak self] routeResult, error in
guard error == .none else {
self?.showMessage("Error:route calculation returned error code \(error.rawValue)")
return
}
guard let result = routeResult, let routes = result.routes, routes.count > 0 else {
self?.showMessage("Error:route result returned is not valid")
return
}
// Let's add the 1st result onto the map
self?.route = routes[0]
self?.updateMapRoute(with: self?.route)
// self?.startNavigation()
}
}
private func updateMapRoute(with route: NMARoute?) {
// remove previously created map route from map
if let previousMapRoute = mapRoute {
mapView.remove(mapObject:previousMapRoute)
}
guard let unwrappedRoute = route else {
return
}
mapRoute = NMAMapRoute(unwrappedRoute)
mapRoute?.traveledColor = .clear
_ = mapRoute.map{ mapView?.add(mapObject: $0) }
// In order to see the entire route, we orientate the
// map view accordingly
if let boundingBox = unwrappedRoute.boundingBox {
geoBoundingBox = boundingBox
mapView.set(boundingBox: boundingBox, animation: .linear)
}
}
in comparison same route presented with leaflet maps.
I believe the problem you have is that you are feeding the Routing API a large number of waypoints, all of which are in close proximity to each other.
You have almost 2000 waypoints in your GPX file (and ~1300 in your cleaned one). Each of these waypoints is less than 10 meters distance from their closest neighbors. This is not the type of data that the Routing API is really designed to work with.
I've experimented with your GPX Trace and I have come up with the following solution: simply skip a bunch of coordinates in your trace.
First, clean up your trace using the Route Matching API (which I believe you have been doing).
Second, pick the first trkpt in the GPX file as your first waypoint for the Routing call. Then skip the next 20 points. Pick the following trkpoint as the second waypoint. Repeat this until you are at the end of the file. Then add the last trkpt in the trace as the final waypoint.
Then call the Routing API and you should get a good match between your trace and your route, without any loops or other weird routing artefacts.
Some notes:
I have picked 20 as the number of traces to skip, because this would put about 200m in between each waypoint. That should be close enough to ensure that the Routing API does not deviate too much from the traced route. For larger traces you may wish to increase that number. For traces in urban environments with lots alternate routes, you may want to use a smaller number.
It's important to clean the data with the Route Matching API first, to avoid picking outliers as waypoints.
Also, you may not wish to use the "avoidHighways" option. Given your use case, there doesn't seem to be a benefit and I could see it causing additional problems.
By now you probably worked it out, but your waypoints are likely landing on bridges or tunnels that are along your route but not on the road you want. I.e. the waypoint is intended to be on the road under the bridge but the routing engine perceives that you want to drive on the bridge.
The routing engine is looping around those roads to drive you on that waypoint on the bridge or in the tunnel.
There is no simple solution to this that I have found.

how to control cars speed using anylogic

i have to simulate a traffic on a highway using anylogic 8 learning edition, what I want to do is the control the car speed on road basis for ex if my car move from road1 to road 2 thru CarMoveTo I want to change the speed when it enters the road2... I tried to use "on enter" and "on exit" of the CarMoveTo but with no success and I even tried to use the Car API with no success too. I think I missed where is the suitable location to write the following code:
if (getRoad().equals("Road2"))
setPreferredSpeed(0, MPH);
Any Help?????
First, I think your getRoad().equals( "Road2" ) may be problematic. getRoad returns a road object according to intelliSense, not a string. Try taking out your quotation marks.
To set the speed at a certain road, try one of the following:
1) Use a stop line and on crossing the line, call your code to set the speed. No need to figure out what road you are on, because the stop line will inherently be on the road of interest.
2) Use a road network descriptor, and call your code "On Enter Road"
If move to only applies to road2, you could also set it there. However, if your move to block gives the car an overall destination that just happens to go through road2, then this would not be the right place, as it would get called just the first time the car enters the move to block.

Rest Server with Z1 Websense

Hi Stackover'followers :). I'm very much new to Stackoverflow. Let me put forward a question I have regarding Instant Contiki. Anybody who has idea on Instant Contiki, zolertia motes, REST Server, is welcomed to resolve it out.
I could successfully work on the two different motes by considering 'z1-websense.c' and 'rest-server-example.c'.
But I want to get the result of 'z1-websense.c' which is the
temperature, by executing the 'rest-server-example.c'.
So, regarding this, there is something to be done in the 'rest-server-example.c' code, may be by calling a function for z1-websense.c, which I'm unable to crack it.
Please help me out. Thanks in advance.
the rest-engine app on Contiki let's you set up resources and handlers for methods called on them.
So, if I understood, you want to tweak the resource GET handlers in er-example-server to taylor onto the z1 mote, in particular a resource for the battery sensor and a resource for the temperature one.
If you take a look at z1-websense.c the values are retrieved and simply scaled (lines 66-79).
static int
get_battery(void)
{
return battery_sensor.value(0);
}
static int
get_temp(void)
{
return temperature_sensor.value(0);
}
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}
static float get_mytemp(void){ return (float) (((get_temp()*2.500)/4096)-0.986)*282;}
Take that code and inject it into the battery and temperature resources you can find hereenter link description here and you are done.
So in the end you will have something like
file res-battery.c, line 60
float battery = ( battery_sensor.value(0) *2.500*2) /4096 ;
You should do similarly for the temperature and you are done.
Remember to deactivate all sensors/resources you are not interested in, since they would take precious memory.
I cannot test it right now, but this should work.