• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ free_and_null函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中free_and_null函数的典型用法代码示例。如果您正苦于以下问题:C++ free_and_null函数的具体用法?C++ free_and_null怎么用?C++ free_and_null使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了free_and_null函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: mod_funcdef_clear

static void mod_funcdef_clear(struct py_function_def *def)
{
	mod_objclear(&def->function);
	mod_objclear(&def->module);
	free_and_null(&def->function_name);
	free_and_null(&def->module_name);
}
开发者ID:ehayon,项目名称:freeradius-server,代码行数:7,代码来源:rlm_python.c


示例2: udf_dirent_free

/*!
  free free resources associated with p_udf_dirent.
*/
bool
udf_dirent_free(udf_dirent_t *p_udf_dirent)
{
  if (p_udf_dirent) {
    p_udf_dirent->fid = NULL;
    free_and_null(p_udf_dirent->psz_name);
    free_and_null(p_udf_dirent->sector);
    free_and_null(p_udf_dirent);
  }
  return true;
}
开发者ID:gencer,项目名称:rufus,代码行数:14,代码来源:udf_fs.c


示例3: sharpel1pca

void sharpel1pca (double *points_XT, int *dataDim, int *q, double *PCs, double *objectives) 
{
 
  ENTITYINFO entityinfo;
  SOLVERINFO  solverinfo;
  PROBLEMINFO  probleminfo;
  
  probleminfo.status = 0;
  int status        = probleminfo.status;

  solverinfo.model = NULL;

  probleminfo.obj       = NULL;
  probleminfo.lb        = NULL;
  probleminfo.ub        = NULL;
  probleminfo.rhs       = NULL;
  probleminfo.matbeg    = NULL;
  probleminfo.matind    = NULL;
  probleminfo.matval    = NULL;
  probleminfo.colname   = NULL;
  probleminfo.PCs       = PCs;
  /*probleminfo.getScores = *getScores;
  probleminfo.scores    = scores;*/
  probleminfo.objectives = objectives;
 
  entityinfo.numentities_n   = dataDim[1];
  entityinfo.numattributes_m = dataDim[0];
  
  entityinfo.points_XT = points_XT; /* transpose of data matrix */

  probleminfo.q = *q; /* desired number of PCs */

  status = allocateMemoryL1Line(&entityinfo, &probleminfo);
  if (status) {
    REprintf ("Unable to allocate memory\n");
    goto TERMINATE;
  }

  status = solveSharpeL1PCA( &entityinfo, &solverinfo, &probleminfo); /* in l1line.c*/
  if (status) {
    REprintf ("Unable to solve.  Terminating...; or done\n");
    goto TERMINATE;
  }

  
TERMINATE:

  free_and_null ((char **) &probleminfo.ratios);     
  free_and_null ((char **) &probleminfo.weights);     
  free_and_null ((char **) &probleminfo.v);     
  free_and_null ((char **) &probleminfo.tosort);

} /* end l1line */
开发者ID:cran,项目名称:pcaL1,代码行数:53,代码来源:sharpel1pca_R.c


示例4: destroy_separator

void destroy_separator(void *obj)
{
	Separator *separator = (Separator *)obj;
	remove_area(&separator->area);
	free_area(&separator->area);
	free_and_null(separator);
}
开发者ID:o9000,项目名称:tint2,代码行数:7,代码来源:separator.c


示例5: cleanup

/* This is run automatically before leaving the program.
   Free allocated resources.
*/
static void
cleanup (void)
{
  if (p) paranoia_free(p);
  if (d) cdda_close(d);
  free_and_null(force_cdrom_device);
  free_and_null(span);
  if(logfile_open) {
      fclose(logfile);
      logfile = NULL;
    }
  if(reportfile_open) {
      fclose(reportfile);
      reportfile = NULL;
    }
}
开发者ID:ShiftMediaProject,项目名称:libcdio-paranoia,代码行数:19,代码来源:cd-paranoia.c


示例6: free_user_cbhandle

static int
free_user_cbhandle  (USER_CBHANDLE *user_cbhandle)
{
   int status = 0; 

   if (user_cbhandle == NULL) goto TERMINATE;
   
   free_and_null ((char **) &user_cbhandle->x);
   free_and_null ((char **) &user_cbhandle->indices);
   free_and_null ((char **) &user_cbhandle->ray);
   free_and_null ((char **) &user_cbhandle->cutval);
   free_and_null ((char **) &user_cbhandle->cutind);
   
   if ( user_cbhandle->lp != NULL ) {
      int local_status = CPXXfreeprob (user_cbhandle->env, &(user_cbhandle->lp) );
      if ( local_status ) {
         fprintf (stderr, "CPXXfreeprob failed, error code %d.\n", status);
         status = local_status;
      }
      else
         user_cbhandle->lp = NULL;
   }

   if ( user_cbhandle->env != NULL ) {
      int local_status = CPXXcloseCPLEX ( &(user_cbhandle->env) );
      if ( local_status ) {
         fprintf (stderr, "CPXXcloseCPLEX failed, error code %d.\n", status);
         status = local_status;
      }
      else
         user_cbhandle->env = NULL;
   }

TERMINATE:

   return status; 

} /* END free_user_cbhandle */
开发者ID:annaPolytech,项目名称:PRD,代码行数:38,代码来源:xbendersatsp.c


示例7: udf_close

/*!
  Close UDF and free resources associated with p_udf.
*/
bool
udf_close (udf_t *p_udf)
{
  if (!p_udf) return true;
  if (p_udf->b_stream) {
    cdio_stdio_destroy(p_udf->stream);
  } else {
    cdio_destroy(p_udf->cdio);
  }

  /* Get rid of root directory if allocated. */

  free_and_null(p_udf);
  return true;
}
开发者ID:gencer,项目名称:rufus,代码行数:18,代码来源:udf_fs.c


示例8: populatebyrow

static int
populatebyrow (CPXENVptr env, CPXLPptr lp,
               int nfoods, double *cost, double *lb, double *ub, 
               int nnutr, double *nutrmin, double *nutrmax,
               double **nutrper)
{
   int status = 0;

   int zero = 0;
   int *ind = NULL;
   int i, j;

   ind = (int*) malloc(nfoods * sizeof(int));
   if ( ind == NULL ) {
      status = CPXERR_NO_MEMORY;
      goto TERMINATE;
   }
   for (j = 0; j < nfoods; j++) {
      ind[j] = j;
   }

   status = CPXnewcols (env, lp, nfoods, cost, lb, ub, NULL, NULL);
   if ( status )  goto TERMINATE;

   for (i = 0; i < nnutr; i++) {
      double rng  = nutrmax[i] - nutrmin[i];

      status = CPXaddrows (env, lp, 0, 1, nfoods, nutrmin+i, "R",
                           &zero, ind, nutrper[i], NULL, NULL);
      if ( status )  goto TERMINATE;

      status = CPXchgrngval (env, lp, 1, &i, &rng);
      if ( status )  goto TERMINATE;
   }

TERMINATE:

   free_and_null ((char **)&ind);

   return (status);

}  /* END populatebyrow */
开发者ID:annaPolytech,项目名称:PRD,代码行数:42,代码来源:diet.c


示例9: exec_instr_pipe

int                     exec_instr_pipe(s_instr                 *instr,
                                        s_list_dup              *list_dup,
                                        int                     *error)
{
  s_instr_pipe          *instr_pipe = NULL;
  int                   filedes[2];
  int                   res = 0;
  s_list_dup            *dp = NULL;
  s_list_dup            *dp2 = NULL;
  s_list_instr_item     *list_instr = NULL;
  int                   fd_in = STDIN_FILENO;

  if (instr == NULL || instr->instr == NULL)
    return (-1);

  instr_pipe = instr->instr;

  list_instr = instr_pipe->list_instr->first;
  for (; list_instr != NULL; list_instr = list_instr->next)
  {
    if (list_instr->next != NULL)
      mpipe(filedes);
    if (list_instr->next != NULL)
      dp = list_dup_insert(list_dup, filedes[1], STDOUT_FILENO);

    if (list_instr != instr_pipe->list_instr->first)
      dp2 = list_dup_insert(dp == NULL ? list_dup : dp, fd_in, STDIN_FILENO);

    res = exec_instr(list_instr->elmt, dp2 == NULL ? dp : dp2, error);
    close_fds(&fd_in, filedes, list_instr->next);
    free_and_null(&dp, &dp2);

    CHECK_ERROR()
  }

  return (res);
}
开发者ID:jclanoe,项目名称:SH,代码行数:37,代码来源:exec_instr_pipe.c


示例10: main


//.........这里部分代码省略.........
      }

      status = CPXgetbase (env, lp, cstat, rstat);
      if ( status ) {
         fprintf (stderr, "Failed to get basis; error %d.\n", status);
         goto TERMINATE;
      }
   }
   else {
      printf ("No basis available\n");
   }

   /* Retrieve solution vector */

   x = (double *) malloc (cur_numcols*sizeof(double));
   if ( x == NULL ) {
      fprintf (stderr, "No memory for solution.\n");
      goto TERMINATE;
   }

   status = CPXgetx (env, lp, x, 0, cur_numcols-1);
   if ( status ) {
      fprintf (stderr, "Failed to obtain primal solution.\n");
      goto TERMINATE;
   }

   /* Write out the solution */

   for (j = 0; j < cur_numcols; j++) {
      printf ( "Column %d:  Value = %17.10g", j, x[j]);
      if ( cstat != NULL ) {
         switch (cstat[j]) {
            case CPX_AT_LOWER:
               basismsg = "Nonbasic at lower bound";
               break;
            case CPX_BASIC:
               basismsg = "Basic";
               break;
            case CPX_AT_UPPER:
               basismsg = "Nonbasic at upper bound";
               break;
            case CPX_FREE_SUPER:
               basismsg = "Superbasic, or free variable at zero";
               break;
            default:
               basismsg = "Bad basis status";
               break;
         }
         printf ("  %s",basismsg);
      }
      printf ("\n");
   }

   /* Display the maximum bound violation. */

   status = CPXgetdblquality (env, lp, &maxviol, CPX_MAX_PRIMAL_INFEAS);
   if ( status ) {
      fprintf (stderr, "Failed to obtain bound violation.\n");
      goto TERMINATE;
   }
   printf ("Maximum bound violation = %17.10g\n", maxviol);

TERMINATE:

   /* Free up the basis and solution */

   free_and_null ((char **) &cstat);
   free_and_null ((char **) &rstat);
   free_and_null ((char **) &x);

   /* Free up the problem, if necessary */

   if ( lp != NULL ) {
      status = CPXfreeprob (env, &lp);
      if ( status ) {
         fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status);
      }
   }

   /* Free up the CPLEX environment, if necessary */

   if ( env != NULL ) {
      status = CPXcloseCPLEX (&env);

      /* Note that CPXcloseCPLEX produces no output,
         so the only way to see the cause of the error is to use
         CPXgeterrorstring.  For other CPLEX routines, the errors will
         be seen if the CPXPARAM_ScreenOutput indicator is set to CPX_ON. */

      if ( status ) {
         char  errmsg[CPXMESSAGEBUFSIZE];
         fprintf (stderr, "Could not close CPLEX environment.\n");
         CPXgeterrorstring (env, status, errmsg);
         fprintf (stderr, "%s", errmsg);
      }
   }

   return (status);

}  /* END main */
开发者ID:annaPolytech,项目名称:PRD,代码行数:101,代码来源:globalqpex1.c


示例11: main


//.........这里部分代码省略.........

   totinv = 0;
   for (j = 0; j < numcols; j++) {
      if ( strncmp (nameptr[j], "inv", 3) ) {
         values[j] = 0.0;
      }
      else {
         values[j] = - 1.0;
      }
   }

   status = CPXprechgobj (env, lp, numcols, indices, values);

   if ( status ) {
      fprintf (stderr,
              "Failed to change to inventory objective.  Status %d\n",
              status);
      goto TERMINATE;
   }

   status = CPXlpopt (env, lp);
   if ( status ) {
      fprintf (stderr, "Optimization on inventory level failed. Status %d.\n",
              status);
      goto TERMINATE;
   }

   solstat = CPXgetstat (env, lp);
   status  = CPXgetobjval (env, lp, &objval);
   if ( status  ||  solstat != CPX_STAT_OPTIMAL ) {
      fprintf (stderr, "Solution failed. Status %d, solstat %d.\n",
               status, solstat);
      goto TERMINATE;
   }

   printf("Solution status %d.\n", solstat);
   printf ("Inventory level after optimization is %g\n", -objval);


   status = CPXgetx (env, lp, x, 0, numcols-1);
   if ( status ) {
      fprintf (stderr, "Failed to obtain primal solution.\n");
      goto TERMINATE;
   }

   printf("Found solution");

   /* Write out the solution */

   printf ("\n");
   for (j = 0; j < numcols; j++) {
      printf ( "%s:  Value = %17.10g\n", nameptr[j], x[j]);
   }


TERMINATE:

   /* Free the filename */

   free_and_null ((char **) &prod);

   /* Free up the basis and solution */

   free_and_null ((char **) &indices);
   free_and_null ((char **) &values);
   free_and_null ((char **) &nameptr);
   free_and_null ((char **) &namestore);
   free_and_null ((char **) &x);


   /* Free up the problem, if necessary */

   if ( lp != NULL ) {
      status = CPXfreeprob (env, &lp);
      if ( status ) {
         fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status);
      }
   }

   /* Free up the CPLEX environment, if necessary */

   if ( env != NULL ) {
      status = CPXcloseCPLEX (&env);

      /* Note that CPXcloseCPLEX produces no output,
         so the only way to see the cause of the error is to use
         CPXgeterrorstring.  For other CPLEX routines, the errors will
         be seen if the CPXPARAM_ScreenOutput indicator is set to CPX_ON. */

      if ( status ) {
         char  errmsg[CPXMESSAGEBUFSIZE];
         fprintf (stderr, "Could not close CPLEX environment.\n");
         CPXgeterrorstring (env, status, errmsg);
         fprintf (stderr, "%s", errmsg);
      }
   }
     
   return (status);

}  /* END main */
开发者ID:annaPolytech,项目名称:PRD,代码行数:101,代码来源:adpreex1.c


示例12: rounddownheur

static int CPXPUBLIC 
rounddownheur (CPXCENVptr env,
               void       *cbdata,
               int        wherefrom, 
               void       *cbhandle,
               double     *objval_p,
               double     *x,
               int        *checkfeas_p,
               int        *useraction_p)
{
   int status = 0;
   
   int       j, cols;
   double    roundobjval;
   int       *feas = NULL;
   CPXCLPptr lp;
   double    *objcoefs = NULL;

   *useraction_p = CPX_CALLBACK_DEFAULT;

   /* Heuristic motivated by knapsack constrained problems.
      Rounding down all fractional values will give an integer
      solution that is feasible, since all constraints are <= 
      with positive coefficients */

   status = CPXgetcallbacklp (env, cbdata, wherefrom, &lp);
   if ( status ) {
      fprintf (stdout, "Can't get lp pointer.");
      goto TERMINATE;
   }

   cols = CPXgetnumcols (env, lp);
   if ( cols <= 0 ) {
      fprintf (stdout, "numcols = %d.", cols);
      status = CPXERR_CALLBACK;
      goto TERMINATE;
   }
   
   objcoefs = (double *) malloc (cols * sizeof (double));
   feas     = (int *)    malloc (cols * sizeof (int));
   if ( objcoefs == NULL || feas == NULL ) {
      fprintf (stdout, "Out of memory.");
      status = CPXERR_CALLBACK;
      goto TERMINATE;
   } 
 
   status = CPXgetobj (env, lp, objcoefs, 0, cols-1);
   if ( status ) {
      fprintf (stdout, "Can't get objective.");
      goto TERMINATE;
   }

   status = CPXgetcallbacknodeintfeas (env, cbdata, wherefrom, feas,
                                       0, cols-1);
   if ( status ) {
      fprintf (stdout,
               "Can't get variable feasible status for node.");
      goto TERMINATE;
   }

   roundobjval = *objval_p;
   for (j = 0; j < cols; j++) {

      /* Set the fractional variable to zero and update
         the objective value */

      if ( feas[j] == CPX_INTEGER_INFEASIBLE ) {
         roundobjval -= x[j] * objcoefs[j];
         x[j] = 0.0;
      }
   }
   *objval_p = roundobjval;

   /* Have CPLEX check the solution for integer feasibility */

   *checkfeas_p = 1;

   /* Tell CPLEX that a solution is being returned */

   *useraction_p = CPX_CALLBACK_SET;

TERMINATE:

   free_and_null ((char **) &objcoefs);
   free_and_null ((char **) &feas);  

   return (status);

} /* END rounddown */
开发者ID:andreasmattas,项目名称:testcode,代码行数:89,代码来源:admipex2.c


示例13: main


//.........这里部分代码省略.........
   

   status = CPXsetdblparam (env, CPXPARAM_MIP_Tolerances_MIPGap,
                            (double) 1e-6);
   if ( status )  goto TERMINATE;

   /* Turn on traditional search for use with control callbacks */

   status = CPXsetintparam (env, CPXPARAM_MIP_Strategy_Search,
                            CPX_MIPSEARCH_TRADITIONAL);
   if ( status )  goto TERMINATE;

   /* Set up to use MIP callback */

   status = CPXsetheuristiccallbackfunc (env, rounddownheur, NULL);
   if ( status )  goto TERMINATE;

   /* Optimize the problem and obtain solution */

   status = CPXmipopt (env, lp);
   if ( status ) {
      fprintf (stderr, "Failed to optimize MIP.\n");
      goto TERMINATE;
   }

   solstat = CPXgetstat (env, lp);
   printf ("Solution status %d.\n", solstat);

   status = CPXgetobjval (env, lp, &objval);
   if ( status ) {
      fprintf (stderr, "Failed to obtain objective value.\n");
      goto TERMINATE;
   }

   printf ("Objective value %.10g\n", objval);

   cur_numcols = CPXgetnumcols (env, lp);

   /* Allocate space for solution */

   x = (double *) malloc (cur_numcols * sizeof (double));
   if ( x == NULL ) {
      fprintf (stderr, "No memory for solution values.\n");
      goto TERMINATE;
   }

   status = CPXgetx (env, lp, x, 0, cur_numcols-1);
   if ( status ) {
      fprintf (stderr, "Failed to obtain solution.\n");
      goto TERMINATE;
   }

   /* Write out the solution */

   for (j = 0; j < cur_numcols; j++) {
      if ( fabs (x[j]) > 1e-10 ) {
         printf ( "Column %d:  Value = %17.10g\n", j, x[j]);
      }
   }


TERMINATE:

   /* Free the solution vector */

   free_and_null ((char **) &x);

   /* Free the problem as allocated by CPXcreateprob and
      CPXreadcopyprob, if necessary */

   if ( lp != NULL ) {
      status = CPXfreeprob (env, &lp);
      if ( status ) {
         fprintf (stderr, "CPXfreeprob failed, error code %d.\n",
                  status);
      }
   }

   /* Free the CPLEX environment, if necessary */

   if ( env != NULL ) {
      status = CPXcloseCPLEX (&env);

      /* Note that CPXcloseCPLEX produces no output, so the only 
         way to see the cause of the error is to use
         CPXgeterrorstring.  For other CPLEX routines, the errors 
         will be seen if the CPXPARAM_ScreenOutput parameter is set to 
         CPX_ON */

      if ( status ) {
         char errmsg[CPXMESSAGEBUFSIZE];
         fprintf (stderr, "Could not close CPLEX environment.\n");
         CPXgeterrorstring (env, status, errmsg);
         fprintf (stderr, "%s", errmsg);
      }
   }
     
   return (status);

} /* END main */
开发者ID:andreasmattas,项目名称:testcode,代码行数:101,代码来源:admipex2.c


示例14: main


//.........这里部分代码省略.........
   solstat = CPXXgetstat (env, lp);
   printf ("\nSolution status: %d\n", solstat);

   /* Write out the objective value */ 

   if ( CPXXgetobjval (env, lp, &objval) ) {
      printf ("Failed to obtain objective value.\n");
   }
   else {
      printf ("Objective value: %17.10e\n", objval);
   }

   if ( solstat == CPXMIP_OPTIMAL ) {
    
      /* Write out the optimal tour */
      
      num_x_cols = CPXXgetnumcols (env, lp);
      x = malloc (num_x_cols * sizeof(*x));
      if ( x == NULL ) {
         fprintf (stderr, "No memory for x array.\n");
         status = -1;
         goto TERMINATE;
      }
      status = CPXXgetx (env, lp, x, 0, num_x_cols-1);
      if ( status ) {
         fprintf (stderr, "Failed to obtain solution, status = %d.\n", status);
         goto TERMINATE;
      }

      succ = malloc (num_nodes * sizeof(*succ));
      if ( succ == NULL ) {
         fprintf (stderr, "No memory for succ array.\n");
         status = -1;
         goto TERMINATE;
      }
      for (j = 0; j < num_nodes; ++j)
         succ[j] = -1;
      for (i = 0; i < num_nodes; ++i) {
         for (j = 0; j < num_nodes; ++j) {
            if ( fabs (x[i * num_nodes + j]) > 1e-03 )
               succ[i] = j;
         }
      }
      printf ("Optimal tour:\n");
      i = 0;
      while ( succ[i] != 0 ) {
         printf ("%d, ", i);
         i = succ[i];
      }
      printf ("%d\n", i);

   } 
   else {
      printf ("Solution status is not CPX_STAT_OPTIMAL\n");
   }
   
TERMINATE:

   /* Free the allocated memory if necessary */

   free_and_null ((char **) &x);
   free_and_null ((char **) &succ);

   if ( arc_cost != NULL ) {
      for (i = 0; i < num_nodes; ++i) {
         free_and_null ((char **) &(arc_cost[i]));
      }
   }
   free_and_null ((char **) &arc_cost);

   status = free_user_cbhandle (&user_cbhandle);
   if ( status ) {
      fprintf (stderr, "free_user_cbhandle failed, status = %d.\n",
               status);
   }
    
   if ( lp != NULL ) {
      int local_status = CPXXfreeprob (env, &lp);
      if ( local_status ) {
         fprintf (stderr, "CPXXfreeprob failed, error code %d.\n",
                  local_status);
         status = local_status;
      }
   }

   /* Free the CPLEX environment, if necessary */

   if ( env != NULL ) {
      int local_status = CPXXcloseCPLEX (&env);
      if ( local_status ) {
         fprintf (stderr, 
                  "Could not close CPLEX environment, status = %d.\n", 
                  local_status);
         status = local_status;
      }
   }
     
   return status;

} /* END main */
开发者ID:annaPolytech,项目名称:PRD,代码行数:101,代码来源:xbendersatsp.c


示例15: read_execp

gboolean read_execp(void *obj)
{
	Execp *execp = (Execp *)obj;

	if (execp->backend->child_pipe < 0)
		return FALSE;

	gboolean command_finished = FALSE;
	while (1) {
		// Make sure there is free space in the buffer
		if (execp->backend->buf_capacity - execp->backend->buf_length < 1024) {
			execp->backend->buf_capacity *= 2;
			execp->backend->buf_output = realloc(execp->backend->buf_output, execp->backend->buf_capacity);
		}
		ssize_t count = read(execp->backend->child_pipe,
		                     execp->backend->buf_output + execp->backend->buf_length,
		                     execp->backend->buf_capacity - execp->backend->buf_length - 1);
		if (count > 0) {
			// Successful read
			execp->backend->buf_length += count;
			execp->backend->buf_output[execp->backend->buf_length] = '\0';
			continue;
		} else if (count == 0) {
			// End of file
			command_finished = TRUE;
			break;
		} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
			// No more data available at the moment
			break;
		} else if (errno == EINTR) {
			// Harmless interruption by signal
			continue;
		} else {
			// Error
			command_finished = TRUE;
			break;
		}
		break;
	}

	if (command_finished) {
		execp->backend->child = 0;
		close(execp->backend->child_pipe);
		execp->backend->child_pipe = -1;
		if (execp->backend->interval)
			execp->backend->timer =
			    add_timeout(execp->backend->interval * 1000, 0, execp_timer_callback, execp, &execp->backend->timer);
	}

	if (!execp->backend->continuous && command_finished) {
		free_and_null(execp->backend->text);
		free_and_null(execp->backend->icon_path);
		if (!execp->backend->has_icon) {
			execp->backend->text = strdup(execp->backend->buf_output);
		} else {
			char *text = strchr(execp->backend->buf_output, '\n');
			if (text) {
				*text = '\0';
				text++;
				execp->backend->text = strdup(text);
			} else {
				execp->backend->text = strdup("");
			}
			execp->backend->icon_path = strdup(execp->backend->buf_output);
		}
		int len = strlen(execp->backend->text);
		if (len > 0 && execp->backend->text[len - 1] == '\n')
			execp->backend->text[len - 1] = '\0';
		execp->backend->buf_length = 0;
		execp->backend->buf_output[execp->backend->buf_length] = '\0';
		execp->backend->last_update_finish_time = time(NULL);
		execp->backend->last_update_duration =
		    execp->backend->last_update_finish_time - execp->backend->last_update_start_time;
		return TRUE;
	} else if (execp->backend->continuous > 0) {
		// Count lines in buffer
		int num_lines = 0;
		char *last = execp->backend->buf_output;
		char *end = NULL;
		for (char *c = execp->backend->buf_output; *c; c++) {
			if (*c == '\n') {
				num_lines++;
				if (num_lines == execp->backend->continuous)
					end = c;
			}
			last = c;
		}
		if (*last && *last != '\n')
			num_lines++;
		if (num_lines >= execp->backend->continuous) {
			if (end)
				*end = '\0';
			free_and_null(execp->backend->text);
			free_and_null(execp->backend->icon_path);
			if (!execp->backend->has_icon) {
				execp->backend->text = strdup(execp->backend->buf_output);
			} else {
				char *text = strchr(execp->backend->buf_output, '\n');
				if (text) {
					*text = '\0';
//.........这里部分代码省略.........
开发者ID:o9000,项目名称:tint2,代码行数:101,代码来源:execplugin.c


示例16: populatebycolumn

static int
populatebycolumn (CPXENVptr env, CPXLPptr lp,
                  int nfoods, double *cost, double *lb, double *ub, 
                  int nnutr, double *nutrmin, double *nutrmax,
                  double **nutrper)
{
   int status = 0;

   int i, j;

   int    zero    = 0;
   int    *ind    = NULL;
   double *val    = NULL;
   char   *sense  = NULL;
   double *rngval = NULL;

   sense = (char*)malloc(nnutr * sizeof(char));
   if ( sense == NULL ) {
      status = CPXERR_NO_MEMORY;
      goto TERMINATE;
   }
   for (i = 0; i < nnutr; i++) {
      sense[i] = 'R';
   }

   val = (double*)malloc(nnutr * sizeof(double));
   if ( val == NULL ) {
      status = CPXERR_NO_MEMORY;
      goto TERMINATE;
   }

   rngval = (double*)malloc(nnutr * sizeof(double));
   if ( rngval == NULL ) {
      status = CPXERR_NO_MEMORY;
      goto TERMINATE;
   }
   for (i = 0; i < nnutr; i++) {
      rngval[i] = nutrmax[i] - nutrmin[i];
   }

   ind = (int*) malloc(nfoods * sizeof(int));
   if ( ind == NULL ) {
      status = CPXERR_NO_MEMORY;
      goto TERMINATE;
   }
   for (i = 0; i < nnutr; i++) {
      ind[i] = i;
   }

   status = CPXnewrows (env, lp, nnutr, nutrmin, sense, rngval, NULL);
   if ( status )  goto TERMINATE;

   for (j = 0; j < nfoods; ++j) {
      for (i = 0; i < nnutr; i++) {
         val[i] = nutrper[i][j];
      }

      status = CPXaddcols (env, lp, 1, nnutr, cost+j, &zero,
                           ind, val, lb+j, ub+j, NULL);
      if ( status )  goto TERMINATE;
   }

TERMINATE:

   free_and_null ((char **)&sense);
   free_and_null ((char **)&rngval);
   free_and_null ((char **)&ind);
   free_and_null ((char **)&val);

   return (status);

}  /* END populatebycolumn */
开发者ID:annaPolytech,项目名称:PRD,代码行数:72,代码来源:diet.c


示例17: setproblemdata

static int
setproblemdata (char **probname_p, int *numcols_p, int *numrows_p, 
                int *objsen_p, double **obj_p, double **rhs_p, 
                char **sense_p, int **matbeg_p, int **matcnt_p, 
                int **matind_p, double **matval_p, 
                double **lb_p, double **ub_p)
{
   char     *zprobname = NULL;     /* Problem name <= 16 characters */        
   double   *zobj = NULL;
   double   *zrhs = NULL;
   char     *zsense = NULL;
   int      *zmatbeg = NULL;
   int      *zmatcnt = NULL;
   int      *zmatind = NULL;
   double   *zmatval = NULL;
   double   *zlb = NULL;
   double   *zub = NULL;
   int      status = 0;

   zprobname = (char *) malloc (16 * sizeof(char)); 
   zobj      = (double *) malloc (NUMCOLS * sizeof(double));
   zrhs      = (double *) malloc (NUMROWS * sizeof(double));
   zsense    = (char *) malloc (NUMROWS * sizeof(char)); 
   zmatbeg   = (int *) malloc (NUMCOLS * sizeof(int));   
   zmatcnt   = (int *) malloc (NUMCOLS * sizeof(int));   
   zmatind   = (int *) malloc (NUMNZ * sizeof(int));   
   zmatval   = (double *) malloc (NUMNZ * sizeof(double));
   zlb       = (double *) malloc (NUMCOLS * sizeof(double));
   zub       = (double *) malloc (NUMCOLS * sizeof(double));

   if ( zprobname == NULL || zobj    == NULL ||
        zrhs      == NULL || zsense  == NULL ||
        zmatbeg   == NULL || zmatcnt == NULL ||
        zmatind   == NULL || zmatval == NULL ||
        zlb       == NULL || zub     == NULL   )  {
      status = 1;
      goto TERMINATE;
   }

   strcpy (zprobname, "example");

   /* The code is formatted to make a visual correspondence 
      between the mathematical linear program and the specific data
      items.   */

     zobj[0]  = 1.0;  zobj[1]    = 2.0;  zobj[2]    = 3.0;

   zmatbeg[0] = 0;    zmatbeg[1] = 2;    zmatbeg[2] = 4;
   zmatcnt[0] = 2;    zmatcnt[1] = 2;    zmatcnt[2] = 2;
      
   zmatind[0] = 0;    zmatind[2] = 0;    zmatind[4] = 0;    zsense[0] = 'L';
   zmatval[0] = -1.0; zmatval[2] = 1.0;  zmatval[4] = 1.0;  zrhs[0]   = 20.0;

   zmatind[1] = 1;    zmatind[3] = 1;    zmatind[5] = 1;    zsense[1] = 'L';
   zmatval[1] = 1.0;  zmatval[3] = -3.0; zmatval[5] = 1.0;  zrhs[1]   = 30.0;

       zlb[0] = 0.0;      zlb[1] = 0.0;          zlb[2] = 0.0;
       zub[0] = 40.0;     zub[1] = CPX_INFBOUND; zub[2] = CPX_INFBOUND;

TERMINATE:
   
   if ( status ) {
      free_and_null ((char **) &zprobname);
      free_and_null ((char **) &zobj);
      free_and_null ((char **) &zrhs);
      free_and_null ((char **) &zsense);
      free_and_null ((char **) &zmatbeg);
      free_and_null ((char **) &zmatcnt);
      free_and_null ((char **) &zmatind);
      free_and_null ((char **) &zmatval);
      free_and_null ((char **) &zlb);
      free_and_null ((char **) &zub);
   }
   else {
      *numcols_p   = NUMCOLS;
      *numrows_p   = NUMROWS;
      *objsen_p    = CPX_MAX;   /* The problem is maximization */
   
      *probname_p  = zprobname;
      *obj_p       = zobj;
      *rhs_p       = zrhs;
      *sense_p     = zsense;
      *matbeg_p    = zmatbeg;
      *matcnt_p    = zmatcnt;
      *matind_p    = zmatind;
      *matval_p    = zmatval;
      *lb_p        = zlb;
      *ub_p        = zub;
   }
   return (status);

}  /* END setproblemdata */
开发者ID:renvieir,项目名称:ioc,代码行数:92,代码来源:lpex8.c


示例18: usersetbranch


//.........这里部分代码省略.........
 
   /* Get solution values and objective coefficients */
 
   x    = malloc (cols * sizeof (*x));
   obj  = malloc (cols * sizeof (*obj));
   feas = malloc (cols * sizeof (*feas));
   if ( x     == NULL ||
        obj   == NULL ||
        feas  == NULL   ) {
      fprintf (stdout, "Out of memory.");
      status = CPXERR_CALLBACK;
      goto TERMINATE;
   }
 
   status = CPXXgetcallbacknodex (env, cbdata, wherefrom, x, 0,
                                  cols-1);
   if ( status ) {
      fprintf (stdout, "Can't get node solution.");
      goto TERMINATE;
   }
 
   status = CPXXgetcallbacknodeobjval (env, cbdata, wherefrom,
                                       &objval);
   if ( status ) {
      fprintf (stdout, "Can't get node objective value.");
      goto TERMINATE;
   }
 
   status = CPXXgetobj (env, lp, obj, 0, cols-1);
   if ( status ) {
      fprintf (stdout, "Can't get obj.");
      goto TERMINATE;
   }
 
   status = CPXXgetcallbacknodeintfeas (env, cbdata, wherefrom, feas,
                                        0, cols-1);
   if ( status ) {
      fprintf (stdout,
               "Can't get variable feasible status for node.");
      goto TERMINATE;
   }
 
   /* Branch on var with largest objective coefficient among those
      with largest infeasibility */
 
   for (j = 0; j < cols; j++) {
      if ( feas[j] == CPX_INTEGER_INFEASIBLE ) {
         xj_inf = x[j] - floor (x[j]);
         if ( xj_inf > 0.5 )  xj_inf = 1.0 - xj_inf;
 
         if ( xj_inf >= maxinf                            &&
              (xj_inf > maxinf || fabs (obj[j]) >= maxobj)  ) {
            bestj  = j;
            maxinf = xj_inf; 
            maxobj = fabs (obj[j]);
         }
      }
   }
 
   /* If there weren't any eligible variables, take default branch */
 
   if ( bestj < 0 ) {
      goto TERMINATE;
   }
 
   /* Now set up node descriptions */
 
   xj_lo = floor (x[bestj]);
 
   /* Up node */
 
   varlu[0] = 'L';
   varbd[0] = xj_lo + 1;
   status = CPXXbranchcallbackbranchbds (env, cbdata, wherefrom,
                                        1, &bestj, varlu, varbd,
                                        objval, NULL, &seqnum1);
   if ( status )  goto TERMINATE;
 
   /* Down node */
 
   varlu[0] = 'U';
   varbd[0] = xj_lo;
 
   status = CPXXbranchcallbackbranchbds (env, cbdata, wherefrom,
                                         1, &bestj, varlu, varbd,
                                         objval, NULL, &seqnum2);
   if ( status )  goto TERMINATE;
 
   /* Set useraction to indicate a user-specified branch */
 
   *useraction_p = CPX_CALLBACK_SET;
 
TERMINATE:
 
   free_and_null ((char **) &x);
   free_and_null ((char **) &obj);
   free_and_null ((char **) &feas); 
   return (status);
 
} /* END usersetbranch */
开发者ID:andreasmattas,项目名称:testcode,代码行数:101,代码来源:xadmipex1.c


示例19: setproblemdata

static int
setproblemdata (char **probname_p, CPXDIM *numcols_p, CPXDIM *numrows_p,
                int *objsen_p, double **obj_p, double **rhs_p,
                char **sense_p, CPXNNZ **matbeg_p, CPXDIM **matcnt_p,
                CPXDIM **matind_p, double **matval_p, double **lb_p,
                double **ub_p, CPXNNZ **qmatbeg_p, CPXDIM **qmatcnt_p,
                CPXDIM **qmatind_p, double **qmatval_p)
{
   char     *zprobname = NULL;     /* Problem name <= 16 characters */
   double   *zobj = NULL;
   double   *zrhs = NULL;
   char     *zsense = NULL;
   CPXNNZ   *zmatbeg = NULL;
   CPXDIM   *zmatcnt = NULL;
   CPXDIM   *zmatind = NULL;
   double   *zmatval = NULL;
   double   *zlb = NULL;
   double   *zub = NULL;
   CPXNNZ   *zqmatbeg = NULL;
   CPXDIM   *zqmatcnt = NULL;
   CPXDIM   *zqmatind = NULL;
   double   *zqmatval = NULL;
   int      status = 0;

   zprobname = malloc (16 * sizeof(*zprobname));
   zobj      = malloc (NUMCOLS * sizeof(*zobj));
   zrhs      = malloc (NUMROWS * sizeof(*zrhs));
   zsense    = malloc (NUMROWS * sizeof(*zsense));
   zmatbeg   = malloc (NUMCOLS * sizeof(*zmatbeg));
   zmatcnt   = malloc (NUMCOLS * sizeof(*zmatcnt));
   zmatind   = malloc (NUMNZ * sizeof(*zmatind));
   zmatval   = malloc (NUMNZ * sizeof(*zmatval));
   zlb       = malloc (NUMCOLS * sizeof(*zlb));
   zub       = malloc (NUMCOLS * sizeof(*zub));
   zqmatbeg  = malloc (NUMCOLS * sizeof(*zqmatbeg));
   zqmatcnt  = malloc (NUMCOLS * sizeof(*zqmatcnt));
   zqmatind  = malloc (NUMQNZ * sizeof(*zqmatind));
   zqmatval  = malloc (NUMQNZ * sizeof(*zqmatval));

   if ( zprobname == NULL || zobj     == NULL ||
        zrhs      == NULL || zsense   == NULL ||
        zmatbeg   == NULL || zmatcnt  == NULL ||
        zmatind   == NULL || zmatval  == NULL ||
        zlb       == NULL || zub      == NULL ||
        zqmatbeg  == NULL || zqmatcnt == NULL ||
        zqmatind  == NULL || zqmatval == NULL  )  {
      status = 1;
      goto TERMINATE;
   }

   strcpy (zprobname, "example");

   /* The code is formatted to make a visual correspondence
      between the mathematical linear program and the specific data
      items.   */

     zobj[0]  = 1.0;   zobj[1]   = 2.0;   zobj[2] = 3.0;

   zmatbeg[0] = 0;     zmatbeg[1] = 2;    zmatbeg[2] = 4;
   zmatcnt[0] = 2;     zmatcnt[1] = 2;    zmatcnt[2] = 2;

   zmatind[0] = 0;     zmatind[2] = 0;    zmatind[4] = 0;     zsense[0] = 'L';
   zmatval[0] = -1.0;  zmatval[2] = 1.0;  zmatval[4] = 1.0;   zrhs[0]   = 20.0;

   zmatind[1] = 1;     zmatind[3] = 1;    zmatind[5] = 1;     zsense[1] = 'L';
   zmatval[1] = 1.0;   zmatval[3] = -3.0; zmatval[5] = 1.0;   zrhs[1]   = 30.0;

       zlb[0] = 0.0;       zlb[1] = 0.0;          zlb[2] = 0.0;
       zub[0] = 40.0;      zub[1] = CPX_INFBOUND; zub[2] = CPX_INFBOUND;

   /* Now set up the Q matrix.  Note that we set the values knowing that
    * we're doing a maximization problem, so negative values go on
    * the diagonal.  Also, the off diagonal terms are each repeated,
    * by taking the algebraic term and dividing by 2 */

   zqmatbeg[0] = 0;     zqmatbeg[1] = 2;     zqmatbeg[2] = 5;
   zqmatcnt[0] = 2;     zqmatcnt[1] = 3;     zqmatcnt[2] = 2;

   /* Matrix is set up visually.  Note that the x1*x3 term is 0, and is
    * left out of the matrix.  */

   zqmatind[0] = 0;     zqmatind[2] = 0;
   zqmatval[0] = -33.0; zqmatval[2] = 6.0;

   zqmatind[1] = 1;     zqmatind[3] = 1;     zqmatind[5] = 1;
   zqmatval[1] = 6.0;   zqmatval[3] = -22.0; zqmatval[5] = 11.5;

                        zqmatind[4] = 2;     zqmatind[6] = 2;
                        zqmatval[4] = 11.5;  zqmatval[6] = -11.0;

TERMINATE:

   if ( status ) {
      free_and_null ((char **) &zprobname);
      free_and_null ((char **) &zobj);
      free_and_null ((char **) &zrhs);
      free_and_null ((char **) &zsense);
      free_and_null ((char **) &zmatbeg);
      free_and_null ((char **) &zmatcnt);
      free_and_null ((char **) &zmatind);
//.........这里部分代码省略.........
开发者ID:annaPolytech,项目名称:PRD,代码行数:101,代码来源:xqpex1.c


示例20: logcallback

static int CPXPUBLIC
logcallback (CPXCENVptr env, void *cbdata, int wherefrom, void *cbhandle)
{
    int status = 0;

    LOGINFOptr info = (LOGINFOptr) cbhandle;
    int        hasincumbent = 0;
    int        newincumbent = 0;
    int        nodecnt;
    int        nodesleft;
    double     objval;
    double     bound;
    double     *x = NULL;


    status = CPXgetcallbackinfo (env, cbdata, wherefrom,
                                 CPX_CALLBACK_INFO_NODE_COUNT, &nodecnt);
    if ( status )  goto TERMINATE;

    status = CPXgetcallbackinfo (env, cbdata, wherefrom,
                                 CPX_CALLBACK_INFO_NODES_LEFT, &nodesleft);
    if ( status )  goto TERMINATE;

    status = CPXgetcallbackinfo (env, cbdata, wherefrom,
                                 CPX_CALLBACK_INFO_MIP_FEAS, &hasincumbent);
    if ( status )  goto TERMINATE;

    if ( hasincumbent ) {
        status = CPXgetcallbackinfo (env, cbdata, wherefrom,
                                     CPX_CALLBACK_INFO_BEST_INTEGER, &objval);
        if ( status )  goto TERMINATE;

        if ( fabs(info->lastincumbent - objval) > 1e-5*(1.0 + fabs(objval)) ) {
            newincumbent = 1;
            info->lastincumbent = objval;
        }
    }

    if ( nodecnt >= info->lastlog + 100  ||  newincumbent ) {
        double walltime 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ free_and_strdup函数代码示例发布时间:2022-05-30
下一篇:
C++ free_all函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap