File: test-async-term.cpp

package info (click to toggle)
soplex 7.1.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,560 kB
  • sloc: cpp: 77,063; sh: 1,125; python: 672; makefile: 667; awk: 243; ansic: 93; php: 15
file content (69 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// test-async-term.cpp
// ~~~~~~~~~
// starts a soplex process and interrupts it from a different thread using the interrupt pointer
// if everything works SoPLEX should abort with [time limit reached].
// the wait time on timer2 might have to be adjusted depending on speed of the machine.
// needs to be compiled with GMP=true BOOST=true BOOST_LIBDIR=<PATH_TO_BOOST_LIBDIR>
//

#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "soplex.h"

class printer
{
public:
  printer(boost::asio::io_context& io)
    : timer1_(io, boost::posix_time::seconds(1)),
      timer2_(io, boost::posix_time::seconds(1)),
      interrupt_(false)
  {
    timer1_.async_wait(
          boost::bind(&printer::runSoplex, this));

    timer2_.async_wait(
          boost::bind(&printer::setInterrupt, this));
  }

  void runSoplex()
  {
     soplex::SoPlex soplex;

     soplex.readFile("../check/instances/scagr25.mps");

     soplex.optimize(&interrupt_);

  }
  void doInterrupt()
  {
     interrupt_ = true;
  }

  void setInterrupt()
  {
      timer2_.expires_at(timer2_.expires_at() + boost::posix_time::millisec(15));

      timer2_.async_wait(
            boost::bind(&printer::doInterrupt, this));
  }

private:
  boost::asio::deadline_timer timer1_;
  boost::asio::deadline_timer timer2_;
  bool interrupt_;
};

int main()
{
  boost::asio::io_context io;
  printer p(io);
  boost::thread t(boost::bind(&boost::asio::io_context::run, &io));
  io.run();
  t.join();

  return 0;
}