Exemplo n.º 1
0
void glp_mem_limit(int limit)
{     ENV *env = get_env_ptr();
      if (limit < 0)
         xerror("glp_mem_limit: limit = %d; invalid parameter\n",
            limit);
      env->mem_limit = xlmul(xlset(limit), xlset(1 << 20));
      return;
}
Exemplo n.º 2
0
static void cleanup (void *instance)
{
    if (!instance) {
        xerror();
    }

    free(instance);
}
Exemplo n.º 3
0
/* Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko */

#include "glpenv.h"
#include "minisat.h"

#if 1 /* by mao */
static void *ymalloc(int size)
{     void *ptr;
      xassert(size > 0);
      ptr = malloc(size);
      if (ptr == NULL)
         xerror("MiniSat: no memory available\n");
      return ptr;
}
Exemplo n.º 4
0
const char *glp_get_row_name(glp_prob *lp, int i)
{     char *name;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_name: i = %d; row number out of range\n",
            i);
      name = lp->row[i]->name;
      return name;
}
Exemplo n.º 5
0
static void loadlist(const char *filename, char ***what, int concat, int even)
{
	FILE *f = NULL;
	char buf[4096] = {0}; size_t l = 0;
	char **old = NULL;
	int i;

	if (!strcmp(filename, "-")) { f = stdin; goto _noopen; }
	f = fopen(filename, "rb");
	if (!f) xerror(filename);

_noopen:
	if (concat) old = what[0];

	what[0] = NULL;
	what[0] = malloc(sizeof(char *));

	for (i = 0;; i++) {
		if (feof(f)) break;
		if (fgets(buf, sizeof(buf)-1, f) == NULL) break;
		l = strlen(buf) > sizeof(buf)-1 ? sizeof(buf)-1 : strlen(buf);
		if (buf[l - 1] == '\n')
			buf[l - 1] = '\0';
		l--;

		what[0] = realloc(what[0], (sizeof(char *) * (i+1)));
		what[0][i] = malloc(l); memset(what[0][i], 0, l);
		strncpy(what[0][i], buf, l);
	}

	fclose(f);

	if (even && !!(i % 2)) {
		what[0] = realloc(what[0], (sizeof(char *) * (i+1)));
		what[0][i] = malloc(1); what[0][i][0] = 0;
		i++;
	}

	if (concat) {
		int x;

		for (x = 0; old[x]; x++, i++) {
			what[0] = realloc(what[0], (sizeof(char *) * (i+1)));
			what[0][i] = malloc(strlen(old[x]) + 1);
			memset(what[0][i], 0, strlen(old[x]) + 1);
			strncpy(what[0][i], old[x], strlen(old[x]));
		}
	}

	if (i) {
		what[0] = realloc(what[0], (sizeof(char *) * (i+1)));
		what[0][i] = NULL;
	}
	else {
		free(what[0]);
		what[0] = falsetext;
	}
}
Exemplo n.º 6
0
void *xdlsym(void *h, const char *symbol)
{     /* obtain address of symbol from dynamically linked library */
      void *ptr;
      xassert(h != NULL);
      ptr = dlsym(h, symbol);
      if (ptr == NULL)
         xerror("xdlsym: %s: %s\n", symbol, dlerror());
      return ptr;
}
Exemplo n.º 7
0
void glp_adv_basis(glp_prob *lp, int flags)
{     if (flags != 0)
         xerror("glp_adv_basis: flags = %d; invalid flags\n", flags);
      if (lp->m == 0 || lp->n == 0)
         glp_std_basis(lp);
      else
         adv_basis(lp);
      return;
}
Exemplo n.º 8
0
double glp_ios_cut_get_mir_delta(glp_tree *tree, int ord){
  glp_prob *mip;
  IOSCUT *cut;
  IOSAUX *aux;
  int j, n, m;
  if ( tree->reason != GLP_ICUTADDED ){
    xerror("glp_ios_cut_get_aux_mir: not called during cut added.\n");
  }
  cut = ios_find_row(tree->local, ord);
  if ( cut == NULL ){
    xerror("glp_ios_cut_get_aux_mir: not called on a cut.\n");
  }
  if ( cut->klass != GLP_RF_MIR ){
    xerror("glp_ios_cut_get_aux_mir: not called on a mir cut.\n");
  }
  aux = cut->aux;
  return aux->mir_delta;
}
Exemplo n.º 9
0
void *xdlsym(void *h, const char *symbol)
{     /* obtain address of symbol from dynamically linked library */
      void *ptr;
      xassert(h != NULL);
      ptr = GetProcAddress(h, symbol);
      if (ptr == NULL)
         xerror("xdlsym: %s: Error %d\n", symbol, GetLastError());
      return ptr;
}
Exemplo n.º 10
0
void glp_ios_branch_upon(glp_tree *tree, int j, int sel)
{     if (!(1 <= j && j <= tree->mip->n))
         xerror("glp_ios_branch_upon: j = %d; column number out of rang"
            "e\n", j);
      if (!(sel == GLP_DN_BRNCH || sel == GLP_UP_BRNCH ||
            sel == GLP_NO_BRNCH))
         xerror("glp_ios_branch_upon: sel = %d: invalid branch selectio"
            "n flag\n", sel);
      if (!(tree->non_int[j]))
         xerror("glp_ios_branch_upon: j = %d; variable cannot be used t"
            "o branch upon\n", j);
      if (tree->br_var != 0)
         xerror("glp_ios_branch_upon: branching variable already chosen"
            "\n");
      tree->br_var = j;
      tree->br_sel = sel;
      return;
}
Exemplo n.º 11
0
void glp_netgen_prob(int nprob, int parm[1+15])
{     int k;
      if (!(101 <= nprob && nprob <= 150))
         xerror("glp_netgen_prob: nprob = %d; invalid problem instance "
            "number\n", nprob);
      for (k = 1; k <= 15; k++)
         parm[k] = data[nprob-101][k];
      return;
}
Exemplo n.º 12
0
int
TestPushEvents(HTTPServer* p_server)
{
  int error = 0;

  xprintf("TESTING SSE (Server-Sent-Events) CHANNEL FUNCTIONS OF THE HTTP-SERVER\n");
  xprintf("=====================================================================\n");
  CString url("/MarlinTest/Events/");
  // Create URL site to listen to events "http://+:port/MarlinTest/Events/"
  HTTPSite* site = p_server->CreateSite(PrefixType::URLPRE_Strong,false,TESTING_HTTP_PORT,url);
  if (site)
  {
    // SUMMARY OF THE TEST
    // --- "--------------------------- - ------\n"
    qprintf("HTTPSite for event streams  : OK : %s\n",(LPCTSTR) site->GetPrefixURL());
  }
  else
  {
    ++error;
    xerror();
    qprintf("Cannot create a HTTP site for: %s\n",(LPCTSTR) url);
    return error;
  }

  site->SetHandler(HTTPCommand::http_get,new SiteHandlerStream());

  // HERE IS THE MAGIC. MAKE IT INTO AN EVENT STREAM HANDLER!!!
  // Modify standard settings for this site
  site->AddContentType("txt","text/event-stream");
  site->SetIsEventStream(true);

  // Start the site explicitly
  if(site->StartSite())
  {
    xprintf("Site started correctly\n");
  }
  else
  {
    ++error;
    xerror();
    qprintf("ERROR STARTING SITE: %s\n",(LPCTSTR)url);
  }
  return error;
}
Exemplo n.º 13
0
static void *yrealloc(void *ptr, int size)
{     xassert(size > 0);
      if (ptr == NULL)
         ptr = malloc(size);
      else
         ptr = realloc(ptr, size);
      if (ptr == NULL)
         xerror("MiniSat: no memory available\n");
      return ptr;
}
Exemplo n.º 14
0
static void run (void *instance, unsigned long sampleCount)
{
    data_t *ins = (data_t *)instance;
    int i;

    if (!ins) {
        xerror();
    }
    if (!ins->output_buffer_left) {
        xerror();
    }
    if (!ins->input_buffer_left) {
        xerror();
    }
    if (!ins->threshold) {
        xerror();
    }

    for (i = 0;  i < sampleCount;  i++) {
        if (ins->input_buffer_left[i] > *ins->threshold) {
            ins->output_buffer_left[i] = *ins->threshold;
        } else if (ins->input_buffer_left[i] < -(*ins->threshold)) {
            ins->output_buffer_left[i] = -(*ins->threshold);
        } else {
            ins->output_buffer_left[i] = ins->input_buffer_left[i];
        }
    }

    if (ins->input_buffer_right) {
        if (!ins->output_buffer_right) {
            xerror();
        }
        for (i = 0;  i < sampleCount;  i++) {
            if (ins->input_buffer_right[i] > *ins->threshold) {
                ins->output_buffer_right[i] = *ins->threshold;
            } else if (ins->input_buffer_right[i] < -(*ins->threshold)) {
                ins->output_buffer_right[i] = -(*ins->threshold);
            } else {
                ins->output_buffer_right[i] = ins->input_buffer_right[i];
            }
        }
    }
}
Exemplo n.º 15
0
double glp_get_col_prim(glp_prob *lp, int j)
{     /*struct LPXCPS *cps = lp->cps;*/
      double prim;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_prim: j = %d; column number out of range\n"
            , j);
      prim = lp->col[j]->prim;
      /*if (cps->round && fabs(prim) < 1e-9) prim = 0.0;*/
      return prim;
}
Exemplo n.º 16
0
double glp_get_row_dual(glp_prob *lp, int i)
{     /*struct LPXCPS *cps = lp->cps;*/
      double dual;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_dual: i = %d; row number out of range\n",
            i);
      dual = lp->row[i]->dual;
      /*if (cps->round && fabs(dual) < 1e-9) dual = 0.0;*/
      return dual;
}
Exemplo n.º 17
0
void glp_set_rii(glp_prob *lp, int i, double rii)
{     if (!(1 <= i && i <= lp->m))
         xerror("glp_set_rii: i = %d; row number out of range\n", i);
      if (rii <= 0.0)
         xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
            i, rii);
      if (lp->valid && lp->row[i]->rii != rii)
      {  GLPAIJ *aij;
         for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
         {  if (aij->col->stat == GLP_BS)
            {  /* invalidate the basis factorization */
               lp->valid = 0;
               break;
            }
         }
      }
      lp->row[i]->rii = rii;
      return;
}
Exemplo n.º 18
0
static int _fullname(char *buffer)
{
	char *name, *h, *d, *s;
	int error;

	if ((name = strdup(buffer)) == NULL)
		error = ENSMEM;
	else
	{
		d = buffer;

		if ((h = strchr(name, ':')) == NULL)
		{
			*d++ = (char) (x_getdrv() + 'A');
			*d++ = ':';
			h = name;
		}
		else
		{
			h++;
			s = name;
			while (s != h)
				*d++ = *s++;
		}

		if (*h == '\\')
		{
			strcpy(d, h);
			error = 0;
		}
		else
		{
#if USE_gemdos
			if ((error = xerror((int) gemdos(71, d, (int) (buffer[0] - 'A' + 1)))) == 0)
#else
			if ((error = xerror(Dgetpath(d, buffer[0] - 'A' + 1))) == 0)
#endif
				make_path(buffer, buffer, h);
		}
		free(name);
	}
	return error;
}
Exemplo n.º 19
0
void glp_set_obj_coef(glp_prob *lp, int j, double coef)
{     if (!(0 <= j && j <= lp->n))
         xerror("glp_set_obj_coef: j = %d; column number out of range\n"
            , j);
      if (j == 0)
         lp->c0 = coef;
      else
         lp->col[j]->coef = coef;
      return;
}
Exemplo n.º 20
0
void glp_set_graph_name(glp_graph *G, const char *name)
{     if (G->name != NULL)
      {  dmp_free_atom(G->pool, G->name, strlen(G->name)+1);
         G->name = NULL;
      }
      if (!(name == NULL || name[0] == '\0'))
      {  int j;
         for (j = 0; name[j] != '\0'; j++)
         {  if (j == 256)
               xerror("glp_set_graph_name: graph name too long\n");
            if (iscntrl((unsigned char)name[j]))
               xerror("glp_set_graph_name: graph name contains invalid "
                  "character(s)\n");
         }
         G->name = dmp_get_atom(G->pool, strlen(name)+1);
         strcpy(G->name, name);
      }
      return;
}
Exemplo n.º 21
0
void xdie(const char *s, ...)
{
	va_list p;

	va_start(p, s);
	xerror(s, p);	
	va_end(p);
	
	abort();
}
Exemplo n.º 22
0
void glp_ios_select_node(glp_tree *tree, int p)
{     IOSNPD *node;
      /* obtain pointer to the specified subproblem */
      if (!(1 <= p && p <= tree->nslots))
err:     xerror("glp_ios_select_node: p = %d; invalid subproblem refere"
            "nce number\n", p);
      node = tree->slot[p].node;
      if (node == NULL) goto err;
      /* the specified subproblem must be active */
      if (node->count != 0)
         xerror("glp_ios_select_node: p = %d; subproblem not in the act"
            "ive list\n", p);
      /* no subproblem must be selected yet */
      if (tree->next_p != 0)
         xerror("glp_ios_select_node: subproblem already selected\n");
      /* select the specified subproblem to continue the search */
      tree->next_p = p;
      return;
}
Exemplo n.º 23
0
double glp_get_row_prim(glp_prob *lp, int i)
{     /*struct LPXCPS *cps = lp->cps;*/
      double prim;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_prim: i = %d; row number out of range\n",
            i);
      prim = lp->row[i]->prim;
      /*if (cps->round && fabs(prim) < 1e-9) prim = 0.0;*/
      return prim;
}
Exemplo n.º 24
0
void glp_scale_prob(glp_prob *lp, int flags)
{     if (flags & ~(GLP_SF_GM | GLP_SF_EQ | GLP_SF_2N | GLP_SF_SKIP |
                    GLP_SF_AUTO))
         xerror("glp_scale_prob: flags = 0x%02X; invalid scaling option"
            "s\n", flags);
      if (flags & GLP_SF_AUTO)
         flags = (GLP_SF_GM | GLP_SF_EQ | GLP_SF_SKIP);
      scale_prob(lp, flags);
      return;
}
Exemplo n.º 25
0
double glp_get_col_dual(glp_prob *lp, int j)
{     /*struct LPXCPS *cps = lp->cps;*/
      double dual;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_dual: j = %d; column number out of range\n"
            , j);
      dual = lp->col[j]->dual;
      /*if (cps->round && fabs(dual) < 1e-9) dual = 0.0;*/
      return dual;
}
Exemplo n.º 26
0
int X11_oops( Display *display, XErrorEvent *ee )
{
    if ( ee->error_code == BadWindow
         || ( ee->request_code == X_GrabButton && ee->error_code == BadAccess )
         || ( ee->request_code == X_GrabKey && ee->error_code == BadAccess )
       ) return 0;

    fprintf( stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code );
    return xerror( display, ee );
}
Exemplo n.º 27
0
double glp_mip_row_val(glp_prob *mip, int i)
{     /*struct LPXCPS *cps = mip->cps;*/
      double mipx;
      if (!(1 <= i && i <= mip->m))
         xerror("glp_mip_row_val: i = %d; row number out of range\n", i)
            ;
      mipx = mip->row[i]->mipx;
      /*if (cps->round && fabs(mipx) < 1e-9) mipx = 0.0;*/
      return mipx;
}
Exemplo n.º 28
0
double glp_mip_col_val(glp_prob *mip, int j)
{     /*struct LPXCPS *cps = mip->cps;*/
      double mipx;
      if (!(1 <= j && j <= mip->n))
         xerror("glp_mip_col_val: j = %d; column number out of range\n",
            j);
      mipx = mip->col[j]->mipx;
      /*if (cps->round && fabs(mipx) < 1e-9) mipx = 0.0;*/
      return mipx;
}
Exemplo n.º 29
0
int glp_add_vertices(glp_graph *G, int nadd)
{     int i, nv_new;
      if (nadd < 1)
         xerror("glp_add_vertices: nadd = %d; invalid number of vertice"
            "s\n", nadd);
      if (nadd > NV_MAX - G->nv)
         xerror("glp_add_vertices: nadd = %d; too many vertices\n",
            nadd);
      /* determine new number of vertices */
      nv_new = G->nv + nadd;
      /* increase the room, if necessary */
      if (G->nv_max < nv_new)
      {  glp_vertex **save = G->v;
         while (G->nv_max < nv_new)
         {  G->nv_max += G->nv_max;
            xassert(G->nv_max > 0);
         }
         G->v = xcalloc(1+G->nv_max, sizeof(glp_vertex *));
         memcpy(&G->v[1], &save[1], G->nv * sizeof(glp_vertex *));
         xfree(save);
      }
      /* add new vertices to the end of the vertex list */
      for (i = G->nv+1; i <= nv_new; i++)
      {  glp_vertex *v;
         G->v[i] = v = dmp_get_atom(G->pool, sizeof(glp_vertex));
         v->i = i;
         v->name = NULL;
         v->entry = NULL;
         if (G->v_size == 0)
            v->data = NULL;
         else
         {  v->data = dmp_get_atom(G->pool, G->v_size);
            memset(v->data, 0, G->v_size);
         }
         v->temp = NULL;
         v->in = v->out = NULL;
      }
      /* set new number of vertices */
      G->nv = nv_new;
      /* return the ordinal number of the first vertex added */
      return nv_new - nadd + 1;
}
Exemplo n.º 30
0
static
int _file_size (FILE *fp, const char *path, size_t *size)
{
  long r;

  if (fseek (fp, 0L, SEEK_END)) {
    xerror (__FILE__ ": can't seek file `%s'", path);
    fclose (fp);
    return 0;
  }

  r = ftell (fp);
  if (r == -1) {
    xerror (__FILE__ ": can't get file size of `%s'", path);
    return 0;
  }

  if (size) *size = (size_t) r;
  return 1;
}