How to stop the OMPL planner after the first solution is found? - c++

I'm using an RRTstar planner from OMPL.
To solve it I use:
ompl::base::PlannerStatus solved = setup.solve(time);
solve() takes a double time value to specify the requested running time of algorithm. How can I request stopping the algorithm right after the first valid solution is found ?
An instance of the class ompl::base::PlannerTerminationCondition can be passed to solve() as well, but I'm not sure how to use it and whether it would be used in this case.

Ok, Mark Moll answered this question in an email to me.
Most planners in OMPL stop after the first solution is found. But the asymptotically optimal planners like RRT* try to optimize the path as long as time permits. This behavior can be changed by calling setCostThreshold with a large value of the optimization objective (by default path length is minimized).

Related

Using BFS/DFS to solve programming task

I am currently trying out Task #2 in the 2016/2017 COCI. Although I have attempted to solve this problem, I couldn't do it.
So, I looked at the solution and it said,
In order to solve this task, we need to find any path Barry can take
from the initial position to any position in the last column. We can
do this by using BFS or DFS algorithm, after which we need to
construct the path. Finally, all that’s left is to format the path
according to the task.
So I went ahead and studied the BFS and DFS algorithm. However, I am not sure how I can implement this algorithm into my program.
Although I can find certain elements in a tree with the algorithm, I don't know how to use it to find a pathway.
So can someone tell my, briefly, how to use the BFS/DFS algorithm to solve the programming problem?
Thanks in advance.
This is the contest page:
http://hsin.hr/coci/archive/2016_2017/contest1_tasks.pdf
What you could do is convert the whole map into a tree.
Here is a diagram I made to demonstrate what I exactly mean:Click here to view the image
Hope that made sense.

GNU Radio simulation stuck

I have attached a screenshot of my design here:
when I start simulating it stuck and only plot a few vectors of data.
I think it's becasue of variable time shift block, it's a hierarchy block, when I connect a constant source to i'ts float input the design works perfectly but when I connect output of short to float it does not work,
I think it's becasue Argmax block produces one output for every vector but the variable time shift needs that output constantly.
how can i fix this?
I've written an answer to this question that you also posted on the discuss-gnuradio mailing list (archive):
Hi Mohammad,
to try, you could just use the repeat block.
Best regards, Marcus
I hope that solved your issue, since I haven't heard back from you :)

c++ mysql_query update returns error if content is similar to existing (but no way to differentiate from normal error)

I'm trying to set up an error detection system in c++ when doing a mysql_query, to check whether the query failed and if so try again (I'm using the mysql libray for Linux). The function mysql_query returns an int which is set to zero for success, and non-zero if failed (the error numbers are available at https://dev.mysql.com/doc/refman/5.0/en/mysql-query.html).
My first problem is that mysql_query only returns 0 or 1 for me, and this would be fine until I try to update a database entry with a similar content to what's already in the database. It also returns an error for that, which is fine on the principle, but as I can't differentiate it from an normal error, my current error detection system would try to repeat the query until it stops returning an error, which never happens. You'll tell me I could check what's in the DB first and then compare it to what I try to update before doing the query, and you would be right, but the code is already very complex and adding this level of complexity on the top would take quite some time.
So I'm wondering if there is a simpler answer to that? Thanks
Like #Mat wrote just use mysql_errno() (see Mysql Docs)
It returns 0 for success or an error code for errors.
Just so you guys know where this error actually came from, if you ever have the same.
I repetitively had mysql errors 2013 and 2006 when performing queries from different threads at the same time, but only after running a certain number of requests. I tried pretty much everything explained here.
Apparently for some reason the connection crashes and I can't do much to avoid it. The only thing that worked for me is to enable automatic reconnect using mysql_options and the option MYSQL_OPT_RECONNECT. It seems like a work around, more than a real fix, but at least my program doesn't crash now!

Disable application after expiry date for trial

I am writing a simple application for a semi-trusted client, and have no say on certain specifics. The client must be given a copy of a binary, myTestApp, which makes use of proprietary code in an external library, libsecrets. It is a Windows application that will run on a few separate Windows 7 laptops. I have been informed that after the application has served its purpose, it will be deleted. I know there is no perfect solution to this, but I would like to implement an expiry date in the program, and hinder efforts to potentially reverse engineer the code, or at least to prevent the contents of libsecrets from being exposed too easily.
So, my first step will be to statically link myTestApp against libsecrets so everything is contained in one binary, so only the needed pieces of libsecrets is included in the final binary, and its interfaces are no longer published.
Second, I want to implement some sort of getTime mechanism that is not naive. Is there anything in Windows that does a "secure" getTime call, so it can't be tricked by changing the time in the system tray or the BIOS?
Thirdly, if there is no "secure" getTime call, I could also modify myTestApp to use NTP to query a trusted time server, and fail if it can't get the time from it or the trial period has elapsed. But this could be fooled by messing with DNS on the gateway, unless there is some sort of certificates mechanism in place to verify the time server. I don't know much about this though, and would need some suggestions on how to implement it.
Next, is there some way to alter the binary so that it is impractical for individuals to attempt to reverse engineer it by viewing the assembly code? Maybe some sort of wrapper that encrypts the binary and requires a third-party authentication tool? Or maybe some sort of certificate I create that is required to run it and expires later?
Finally, is there any software out there (ie: packaging or publishing software) that can do this for me, either by repacking the final .exe or as some sort of plugin for Microsoft Visual Studio?
Thank you all in advance.
Edit: This is NOT meant to be a bullet proof system, and if it fails, that is acceptable. I just want to make it inconvenient for a non-technical person to attempt to crack. The people using it are technical Luddites, and the only way the software would be cracked is if they hired someone to do it. Since the names and company name are watermarked into the application, and only one person could benefit from its use, it's unlikely they would redistribute it.
You can't make things complete secure, but you can make it hard(er).
Packing with UPX adds some level of complexity to the hacker.
You can check at runtime if you're running under a debugger in several places or if you're running under a virtual machine.
You can encrypt a DLL you're using and load it manually (complicated).
You can write a loader that checks a hash of your application and your application can check the hash of the loader.
You can get the system time and compare it to a system time you already wrote to disk and see that it's monotonic.
All depends on the level of protection you want.
If you go to PirateBay or any other torrent site, you'll see that everything get's hacked if hackers are interested.
There is one way to make it really difficult for them to use it after expiry. The main theme of this trick is to make your expiration date independent of system time and make it depend on hours passed, irrespective of whatever the system time may be.
you will have to create a separate thread to perform this task.
Suppose you want the application to expire after they use it 70 hours.
Create a binary file called "record", and store any number in it, which should be hard to guess (I will tell you latter why you have to put this number in binary file).
When your application starts, it checks if that number is present there if yes, your application should get the current time, and store it in that file along with hour=1 (replacing the already present number), and the thread you created should keep on checking if hour in system time has changed or not, when it changes store current time in that file along with hour=2. A time will come when hour=70.
Add this code at two places inside that thread and on the start of your applicaiton
/*the purpose of storing current time is to find out later if hour has changed or not*/
/*read hour from file.*/
if(hour==70)
{
cout<<"Your trial period has expired"<<endl;
return EXIT_SUCESS;
}
now when ever hour=70 application will not work.
Earlier I told you to keep any number in your binary file, when ever they will run your application, binary file will be read and if that number is found there your application will replace it with current time and hour=1, now suppose they use your application for 5 hours and close it and run it after some time, now when your application will be run it will check that binary file if that number has been replaced with time stored previously and hour=5 it means now you will have to store current time along with hour=stored hour in file +1; . In this even if they change time or do anything else it will not effect your expiration period. Because now your expiration checking is not based on system time any more, it is now based on hours passed, irrespective whatever the time may be.
The absence of that number indicates file is not being accessed for first time and currently present hour in file should be incremented, and use binary file so that client can't see that number.
One last thing
Your binary file's format should be like this
current time, hour="any number", another_secret_number
another_secret_number will be placed so that even if they any how change your binary they will not be able to put that another_secret_number there because they don't know it. It means while reading your binary file you will have to make sure that, the end of any entry in your binary file contains "another_secret_number" at end.
For checking purposes both hidden numbers will also be hard coded in your code, which surely they can't see, and they can't read the binary also, so there is no way they can know them.
I hope it will help you.
Nothing stop the hackers!!!
Your question is like a a searching needle at the hay.
Assembly is large room for the responses.
You may thing only hrder, nothing, never stop 'bad' persons.
For UPX: Is well known, dont use it!!!

Need to find the time of the last boot from a .cpp using linux ubuntu?

So I am very new to C++ and Linux and i need to find the time of the last boot from a c++ file. I have been using /proc files for the other info. I am not looking for up time.
I was trying to find a way to execute the "last reboot" command from my .cpp file but i cant figure this out. Is this possible, or is there a way to find the current time so i can subtract up time form the current?
Very lost...
This is homework by the way, but i have completed every other section and am just tied up on this one small part.
Also i have goggled for hours and just cant find a way... Am i misinterpreting something and its more simple then I am making it?
Just need the time of the last system boot
Thanks!
Get the current time using time (2) and subtract the number of seconds since boot that you get from sysinfo (2).
If you want the result in a nice, displayable format, use ctime (3) to turn it into a date/time string.
Figured it out with the /var/log/syslog not perfect since it will only work for 5 weeks but i think its sufficient for my assignment thanks all!