Example #1
0
    vec bokhoven::solve(const vec& q, const stop& s, vec x ) const {
      const natural n = lcp.dim();
      
      assert(q.rows() == int(n));
      
      if(x.empty()) { x = vec::Zero(n); }
      assert( x.rows() == q.rows() );
      
      const mat& M = lcp.M;
      
      algo::iter_eps(s, [&](real& eps) {
	  
	  x.each([&](natural i ) {
	      const real x_i = x(i);
	      
	      x(i) = (q(i) - this->P.row(i).dot(x) + std::abs( x(i) ) - M.row(i).dot(x.array().abs().matrix()) ) / this->d(i);
	      
	      const real diff = x(i) - x_i;
	      eps += diff * diff;
	    });
	  eps = std::sqrt(eps);
	});
      
      return (x.array().abs() + x.array());
    }
Example #2
0
static void
pidclean ()
{
  for (; !pidfiles.empty (); pidfiles.pop_front ()) {
    pidfile &pf = pidfiles.front ();
    struct stat sb;
    if (!stat (pf.path, &sb)
	&& sb.st_dev == pf.sb.st_dev
	&& sb.st_ino == pf.sb.st_ino)
      unlink (pf.path);
  }
}
static void
launchservers ()
{
  for (sfssrv *nsp, *sp = services.first; sp; sp = nsp) {
    nsp = services.next (sp);
    sp->launch ();
  }

  if (listenaddrs.empty () && sfs_defport) {
    sockaddr_in *sinp = New sockaddr_in;
    bzero (sinp, sizeof (*sinp));
    sinp->sin_family = AF_INET;
    sinp->sin_port = htons (SFS_PORT);
    sinp->sin_addr.s_addr = htonl (INADDR_ANY);
    listenaddrs.push_back (reinterpret_cast<sockaddr *> (sinp));
  }

  if (listenaddrs.empty ())
    whatport (sfshostname (), wrap (setaddrs));
  else
    dolisten ();
}
Example #4
0
void results(const mat& Q, const vec& c,
	     const mat& A, const vec& b, 
	     const vec& x,
	     vec reference = vec()) {
  // std::cout << "solution: " << x.transpose() << std::endl; 

  using namespace std;
  
  const math::natural m = c.rows();
  const math::natural n = b.rows();

  cout << "violation: " << (A * x - b).cwiseMin( vec::Zero(n) ).squaredNorm() / m << endl;
  cout << "obj: " << x.dot( 0.5 * (Q * x) + c ) << endl;

  if(!reference.empty()) {
    core::log("error:", (x - reference).norm() );
  }
  
  cout << endl;

}
static void
dolisten ()
{
  for (sockaddr **sp = listenaddrs.base (); sp < listenaddrs.lim (); sp++) {
    sockaddr_in *sinp = reinterpret_cast<sockaddr_in *> (*sp);
    int fd = inetsocket (SOCK_STREAM, ntohs (sinp->sin_port),
			 ntohl (sinp->sin_addr.s_addr));
    if (fd < 0)
      warn ("could not bind TCP port %d: %m\n", ntohs (sinp->sin_port));
    else {
      if (sinp->sin_addr.s_addr == htonl (INADDR_ANY))
	warn ("listening on TCP port %d\n", ntohs (sinp->sin_port));
      else
	warn ("listening on %s TCP port %d\n",
	      inet_ntoa (sinp->sin_addr), ntohs (sinp->sin_port));
      listeners.push_back (New refcounted<listener> (fd));
    }
  }

  if (listeners.empty ())
    fatal ("no TCP ports to listen on\n");

  hup_lock = false;
}
Example #6
0
void FrameBuffer::validateNewAttachments(const vec<sptr<Texture2D>> &attachments)
{
    SL_DEBUG_PANIC(attachments.empty(), "Frame buffer must have at least one attachment");

    auto width = (std::numeric_limits<u32>::max)(), height = (std::numeric_limits<u32>::max)();
    auto depthAttachmentCount = 0;
    for (const auto &attachment : attachments)
    {
        if (attachment->format() == TextureFormat::Depth24)
            SL_DEBUG_PANIC(++depthAttachmentCount > 1, "Frame buffer can only have one depth attachment");

        const auto size = attachment->dimensions();
        if (width == (std::numeric_limits<u32>::max)())
        {
            width = static_cast<u32>(size.x());
            height = static_cast<u32>(size.y());
        }
        else
        {
            SL_DEBUG_PANIC(static_cast<u32>(size.x()) != width || static_cast<u32>(size.y()) != height,
                "Frame buffer attachments must have same dimentions");
        }
    }
}
Example #7
0
	double worst() {
		return best.empty()
			? -std::numeric_limits< double >::max()
			: *best.rbegin();
	}
Example #8
0
static void
unixserv_cleanup ()
{
  while (!sockets.empty ())
    unlink (sockets.pop_front ());
}