Z3: timeout for optimize in C++ - c++

I'm trying to understand how to set a timeout for the optimize class of Z3 using C++ API.
This i my code:
context c;
optimize opt(c);
z3::params par(c);
par.set("timeout", 1000);
opt.set(par);
But I get "unknown parameter 'timeout'" exception on the line opt.set(par). Is it possible to set the timeout for the optimize class (after the timeout, I would like to obtain the best solution found)?
Thank you!

I know this is an old question, but if anyone's still looking for an answer, you need:
Z3_global_param_set("timeout", timeout);
And your timeout should be given as a C string.

Related

How can I read undefined number of bytes from com port, using boost?

I'm trying to write and read data from com port. I' using
write(*ioboard.port, buffer(cpayload, cpayload.size()));
for writing and i have some troubles with receiving answer.
I tried different variants
int m = read(*ioboard.port, buffer(answer, 1));
int m = read(*ioboard.port, buffer(answer, 1024));
int m = ioboard.port->read_some(buffer(answer));
In first case I received answer after first call of write-read pair and no answer after second: fanction read glitching. In second case I didn't receive answer after first call: again due to the read function. Third works the same way as first. So now I need reboot my devise to send it two commands!
How should I read, if I know maximum data size, but do not know how many bytes, I'll get in particular way.
It happend because nothing was in that port. I have no deep understanding of what happend, but I solved this problem for now by creating symblink to /dev/ttyACM0 and connecting to it. Don't understand why so happened - seems that only discriptor was changed. – voronwe
If you are okay with using Qt tool kit try doc.qt.io/qt-5/qserialport.html

Timed Indexed Color sets in CPN Tools that results in Unhandled Exception Error

I am using CPN Tools to model a distributed system. CPN Tools uses CPN ML an extension of SML. The project homepage is: cpntools.org
I started with a simple model and when I try to make a particular indexed color set timed, I get an "Internal error". There is another indexed colorset within my Petri-net model that is timed and works correctly. I am not sure how I can troubleshoot since I don't understand the error message. Could you help me interpret the error message or give me some hints on what I could be doing wrong?
The model is:
http://imgur.com/JUjPRHK
The declarations of the model are:
http://imgur.com/DvvpyvH
The error message is:
Internal error: Compile error when generating code. Caught error.../compiler/TopLevel/interact/evalloop.sml:296.17-296.20../compiler/TopLevel/interact/evalloop.sml:44.55../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
structure CPN`TransitionID1413873858 = struct ... end (* see simulator debug info for full code *)
simglue.sml:884.12-884.43
"
Thank you~
I know this is an old question, but I run in the same problem and wasted too much time on this, so maybe it will help someone else in the future.
I didn't understand exactly the reason for this, but it seems the problem appears when you play with time values on an arch that ends to a transition (I was updating an integer value to the current time, using IntInf.toInt(time())). Now, if I move the code on the outgoing arch of that transition (that is: the one that ends in a place) there is no error.

ACE debugging: How to cause msg queue full?

I am using the method:
ACE_Task::putq (ACE_Message_Block *mb, ACE_Time_Value *tv)
Here is the line where I call it:
ret = putq(mb, const_cast(&ACE_Time_Value::zero));
What I am basically trying is that I need to get regular errors
EWOULDBLOCK and ESHUTDOWN from
int lastErr = ACE_OS::last_error();
in order to debug it right away...
So my question is, it there a simple way how to force such errors ?
I've already tried this:
while ( ret >= 0 )
ret = putq(mb, const_cast(&ACE_Time_Value::max_time));
but my thread gets stuck after few calls and never returns from putq...
Many thanx in advance for hints !
Peter
I think for the first part (EWOULDBLOCK) i can just use:
ACE_Svc_Handler::msg_queue()->high_water_mark(MAX_BUF_SIZE_BYTES);
ACE_Svc_Handler::msg_queue()->low_water_mark(MIN_BUF_SIZE_BYTES);
I assume these fit my needs and what I observe is exactly what I need.
The envoking of ESHUTDOWN error is another problem, and you can simulate it by putting appropriately putting slow down sleep methods.

Read/Write files with UNC path - in c++

I wrote a bit of code that reads/writes stuff...
I would like to add an option to read/write to UNC paths.
A bit of code:
if (boost::filesystem::exists (file_name))
{
std::ifstream in_file(file_name.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
if(in_file.is_open())
{
in_file.read(...);
in_file.close();
}
}
If the network share I am trying to use has been used before, this works.
But if I try with a share from a computer that I have not seen before, I get error:
boost::filesystem::status: Logon failure: unknown user name or bad password: "\\xx\test.txt"
I'd like to avoid the exception, check the boost::filesystem::status for... what ? Looking in documentation, it seems that it can tell me if I have a regular file, or a directory... but how can I check if I have the correct permissions ?
Is there a way to actually send in the user name and password ?
Edit: found that I could call
Net Use \\yourUNC\path /user:uname password
also:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa375187(v=vs.85).aspx
I think either of these would make the code platform dependent ?
Also, if I do log in every time - in a sequence of 10000 calls, this would result in serious slowing down ?
Is there any way to check if the user is logged in ?
Note: I am using boost 1.47 - mostly windows but I'd like to be platform independent.
Thank you.
The only way I found that I can check rights was to try... catch surrounding a check for file exist call.
If the try fails, it means I don't have rights and can call system("Net Use...")
This way, I only have to log in once even if I read/write 10,000 files...
I don't like the fact that I have to use try... catch, if there is a better way, and I'll find it, I'll update - if anyone knows of a better way, please let me know.

Win32 C/C++ checking if two instances of the same program use the same arguments

I have an application and I want to be able to check if (for instance) two instances of it used the same arguments on execution. To make it clearer:
myapp 1 2
myapp 1 3
This isn't a Singleton design pattern problem as I can have more than one instance running. I though about checking the running processes, but it seems that I can only get the process name and that doesn't help me.
Writing a file on startup and then having other instances check if that file exists isn't viable due to abnormal program termination which would leave me hanging.
In Linux I solved this by checking /proc/pid/cmdline and parsing the information there.
Does anyone have any idea if I can do something similar on windows?
Cheers
You can do this via WMI's Win32_Process class.
You want wmic.exe. Try something like:
wmic.exe process list | findstr myapp.exe
Then sort it / parse it / whatever you need to do.
wmic is really a great tool to have.
I ended up using this script instead of filling up my code with WMI calls:
wmic process where "name='cmd.exe'" get CommandLine > list.txt
works great!
cheers and thanks you Seth and Reed
After some thinking I decided to do things a bit simpler...
Implementing a mutex and checking it's existence is. As I needed to check if the instances started with the same parameters and not if the same application was started, I just needed to decide on the mutex name in runtime!
so...
sprintf(cmdstr,"myapp_%i_%i",arg1,arg2);
DWORD m_dwLastError;
m_hMutex = CreateMutex(NULL, FALSE, cmdstr);
m_dwLastError = GetLastError();
if(ERROR_ALREADY_EXISTS == m_dwLastError)
{
found_other = true;
}
and that's it! no parsing, no wmi, no windows development sdk...
Cheers to you all!