Exemplo n.º 1
0
static void
set_alloced_zoom(void)
{
copy_form(&vf,zoom_form);	/* copy unzoomed screen to zoom_form */
render_form = zoom_form;
vs.zoom_mode = 1;
make_dw();
zoom_it();
}
Exemplo n.º 2
0
unset_zoom()
{
copy_form(zoom_form, &vf);	
free_screen(zoom_form);
zoom_form = NULL;
vs.zoom_mode = 0;
render_form = &vf;
make_dw();
}
Exemplo n.º 3
0
static int
set_zoom(void)
{
if ((zoom_form = alloc_screen())!=NULL)
	{
	copy_form(&uf,zoom_form);	/* save undo screen */
	copy_form(&vf,&uf);		/* save undo for marqi routines */
	rub_in_place(vs.zoomx,vs.zoomy,vs.zoomx+vs.zoomw-1,vs.zoomy+vs.zoomh-1);
	if (PJSTDN)	/* move zoom box... */
		{
		move_box(&vs.zoomx,&vs.zoomy,vs.zoomw,vs.zoomh);
		clip_zoom();
		}
	copy_form(zoom_form, &uf);	/* replace undo buffer */
	set_alloced_zoom();
	return(1);
	}
else
	{
	return(0);
	}
}
Exemplo n.º 4
0
int npp_hidden_covering(NPP *npp, NPPROW *row)
{     /* identify hidden covering inequality */
      NPPROW *copy;
      NPPAIJ *aij;
      struct elem *ptr, *e;
      int kase, ret, count = 0;
      double b;
      /* the row must be inequality constraint */
      xassert(row->lb < row->ub);
      for (kase = 0; kase <= 1; kase++)
      {  if (kase == 0)
         {  /* process row lower bound */
            if (row->lb == -DBL_MAX) continue;
            ptr = copy_form(npp, row, +1.0);
            b = + row->lb;
         }
         else
         {  /* process row upper bound */
            if (row->ub == +DBL_MAX) continue;
            ptr = copy_form(npp, row, -1.0);
            b = - row->ub;
         }
         /* now the inequality has the form "sum a[j] x[j] >= b" */
         ret = hidden_covering(npp, ptr, &b);
         xassert(0 <= ret && ret <= 2);
         if (kase == 1 && ret == 1 || ret == 2)
         {  /* the original inequality has been identified as hidden
               covering inequality */
            count++;
#ifdef GLP_DEBUG
            xprintf("Original constraint:\n");
            for (aij = row->ptr; aij != NULL; aij = aij->r_next)
               xprintf(" %+g x%d", aij->val, aij->col->j);
            if (row->lb != -DBL_MAX) xprintf(", >= %g", row->lb);
            if (row->ub != +DBL_MAX) xprintf(", <= %g", row->ub);
            xprintf("\n");
            xprintf("Equivalent covering inequality:\n");
            for (e = ptr; e != NULL; e = e->next)
               xprintf(" %sx%d", e->aj > 0.0 ? "+" : "-", e->xj->j);
            xprintf(", >= %g\n", b);
#endif
            if (row->lb == -DBL_MAX || row->ub == +DBL_MAX)
            {  /* the original row is single-sided inequality; no copy
                  is needed */
               copy = NULL;
            }
            else
            {  /* the original row is double-sided inequality; we need
                  to create its copy for other bound before replacing it
                  with the equivalent inequality */
               copy = npp_add_row(npp);
               if (kase == 0)
               {  /* the copy is for upper bound */
                  copy->lb = -DBL_MAX, copy->ub = row->ub;
               }
               else
               {  /* the copy is for lower bound */
                  copy->lb = row->lb, copy->ub = +DBL_MAX;
               }
               /* copy original row coefficients */
               for (aij = row->ptr; aij != NULL; aij = aij->r_next)
                  npp_add_aij(npp, copy, aij->col, aij->val);
            }
            /* replace the original inequality by equivalent one */
            npp_erase_row(npp, row);
            row->lb = b, row->ub = +DBL_MAX;
            for (e = ptr; e != NULL; e = e->next)
               npp_add_aij(npp, row, e->xj, e->aj);
            /* continue processing upper bound for the copy */
            if (copy != NULL) row = copy;
         }
         drop_form(npp, ptr);
      }
      return count;
}
Exemplo n.º 5
0
int npp_implied_packing(NPP *npp, NPPROW *row, int which,
      NPPCOL *var[], char set[])
{     struct elem *ptr, *e, *i, *k;
      int len = 0;
      double b, eps;
      /* build inequality (3) */
      if (which == 0)
      {  ptr = copy_form(npp, row, -1.0);
         xassert(row->lb != -DBL_MAX);
         b = - row->lb;
      }
      else if (which == 1)
      {  ptr = copy_form(npp, row, +1.0);
         xassert(row->ub != +DBL_MAX);
         b = + row->ub;
      }
      /* remove non-binary variables to build relaxed inequality (5);
         compute its right-hand side b~ with formula (6) */
      for (e = ptr; e != NULL; e = e->next)
      {  if (!(e->xj->is_int && e->xj->lb == 0.0 && e->xj->ub == 1.0))
         {  /* x[j] is non-binary variable */
            if (e->aj > 0.0)
            {  if (e->xj->lb == -DBL_MAX) goto done;
               b -= e->aj * e->xj->lb;
            }
            else /* e->aj < 0.0 */
            {  if (e->xj->ub == +DBL_MAX) goto done;
               b -= e->aj * e->xj->ub;
            }
            /* a[j] = 0 means that variable x[j] is removed */
            e->aj = 0.0;
         }
      }
      /* substitute x[j] = 1 - x~[j] to build knapsack inequality (8);
         compute its right-hand side beta with formula (11) */
      for (e = ptr; e != NULL; e = e->next)
         if (e->aj < 0.0) b -= e->aj;
      /* if beta is close to zero, the knapsack inequality is either
         infeasible or forcing inequality; this must never happen, so
         we skip further analysis */
      if (b < 1e-3) goto done;
      /* build set P as well as sets Jp and Jn, and determine x[k] as
         explained above in comments to the routine */
      eps = 1e-3 + 1e-6 * b;
      i = k = NULL;
      for (e = ptr; e != NULL; e = e->next)
      {  /* note that alfa[j] = |a[j]| */
         if (fabs(e->aj) > 0.5 * (b + eps))
         {  /* alfa[j] > (b + eps) / 2; include x[j] in set P, i.e. in
               set Jp or Jn */
            var[++len] = e->xj;
            set[len] = (char)(e->aj > 0.0 ? 0 : 1);
            /* alfa[i] = min alfa[j] over all j included in set P */
            if (i == NULL || fabs(i->aj) > fabs(e->aj)) i = e;
         }
         else if (fabs(e->aj) >= 1e-3)
         {  /* alfa[k] = max alfa[j] over all j not included in set P;
               we skip coefficient a[j] if it is close to zero to avoid
               numerically unreliable results */
            if (k == NULL || fabs(k->aj) < fabs(e->aj)) k = e;
         }
      }
      /* if alfa[k] satisfies to condition (13) for all j in P, include
         x[k] in P */
      if (i != NULL && k != NULL && fabs(i->aj) + fabs(k->aj) > b + eps)
      {  var[++len] = k->xj;
         set[len] = (char)(k->aj > 0.0 ? 0 : 1);
      }
      /* trivial packing inequality being redundant must never appear,
         so we just ignore it */
      if (len < 2) len = 0;
done: drop_form(npp, ptr);
      return len;
}
Exemplo n.º 6
0
int npp_reduce_ineq_coef(NPP *npp, NPPROW *row)
{     /* reduce inequality constraint coefficients */
      NPPROW *copy;
      NPPAIJ *aij;
      struct elem *ptr, *e;
      int kase, count[2];
      double b;
      /* the row must be inequality constraint */
      xassert(row->lb < row->ub);
      count[0] = count[1] = 0;
      for (kase = 0; kase <= 1; kase++)
      {  if (kase == 0)
         {  /* process row lower bound */
            if (row->lb == -DBL_MAX) continue;
#ifdef GLP_DEBUG
            xprintf("L");
#endif
            ptr = copy_form(npp, row, +1.0);
            b = + row->lb;
         }
         else
         {  /* process row upper bound */
            if (row->ub == +DBL_MAX) continue;
#ifdef GLP_DEBUG
            xprintf("U");
#endif
            ptr = copy_form(npp, row, -1.0);
            b = - row->ub;
         }
         /* now the inequality has the form "sum a[j] x[j] >= b" */
         count[kase] = reduce_ineq_coef(npp, ptr, &b);
         if (count[kase] > 0)
         {  /* the original inequality has been replaced by equivalent
               one with coefficients reduced */
            if (row->lb == -DBL_MAX || row->ub == +DBL_MAX)
            {  /* the original row is single-sided inequality; no copy
                  is needed */
               copy = NULL;
            }
            else
            {  /* the original row is double-sided inequality; we need
                  to create its copy for other bound before replacing it
                  with the equivalent inequality */
#ifdef GLP_DEBUG
               xprintf("*");
#endif
               copy = npp_add_row(npp);
               if (kase == 0)
               {  /* the copy is for upper bound */
                  copy->lb = -DBL_MAX, copy->ub = row->ub;
               }
               else
               {  /* the copy is for lower bound */
                  copy->lb = row->lb, copy->ub = +DBL_MAX;
               }
               /* copy original row coefficients */
               for (aij = row->ptr; aij != NULL; aij = aij->r_next)
                  npp_add_aij(npp, copy, aij->col, aij->val);
            }
            /* replace the original inequality by equivalent one */
            npp_erase_row(npp, row);
            row->lb = b, row->ub = +DBL_MAX;
            for (e = ptr; e != NULL; e = e->next)
               npp_add_aij(npp, row, e->xj, e->aj);
            /* continue processing upper bound for the copy */
            if (copy != NULL) row = copy;
         }
         drop_form(npp, ptr);
      }
      return count[0] + count[1];
}