Changeset 3035


Ignore:
Timestamp:
May 8, 2020 4:27:09 PM (2 months ago)
Author:
unxusr
Message:

C interface: query conflict graph

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Cbc_C_Interface.cpp

    r3032 r3035  
    4949#include "CbcMipStartIO.hpp"
    5050#include "ClpMessage.hpp"
     51#include "CoinStaticConflictGraph.hpp"
    5152#include <OsiAuxInfo.hpp>
    5253#include "CoinFileIO.hpp"
     
    257258  double *colValuesMS;
    258259  int charSpaceMS;
     260
     261  /* space to query conflict graph */
     262  size_t cg_space;
     263  size_t *cg_neighs;
     264  bool *cg_iv;
     265
    259266
    260267  // parameters
     
    10911098    free(model->sosElWeight);
    10921099    free(model->sosType);
     1100  }
     1101
     1102  if (model->cg_space) {
     1103    free( model->cg_iv );
     1104    free( model->cg_neighs );
    10931105  }
    10941106
     
    34543466}
    34553467
     3468
     3469/** @brief Creates (it not yet) the conflict graph  */
     3470void
     3471Osi_checkCGraph( void *osi ) {
     3472  OsiSolverInterface *solver = (OsiSolverInterface *)(osi);
     3473  solver->checkCGraph();
     3474}
     3475
     3476/** @brief Returns the conflict graph */
     3477CBCSOLVERLIB_EXPORT const void * CBC_LINKAGE
     3478Osi_CGraph( void *osi ) {
     3479  OsiSolverInterface *solver = (OsiSolverInterface *)(osi);
     3480  return solver->getCGraph();
     3481}
     3482
     3483size_t CG_nodes( void *cgraph ) {
     3484  const CoinStaticConflictGraph *cg = (CoinStaticConflictGraph *)cgraph;
     3485  return cg->size();
     3486}
     3487
     3488char CG_conflicting( void *cgraph, size_t n1, size_t n2 ) {
     3489  const CoinStaticConflictGraph *cg = (CoinStaticConflictGraph *)cgraph;
     3490  return (char) cg->conflicting(n1, n2);
     3491}
     3492
     3493/** @brief Density of the conflict graph */
     3494double CG_density( void *cgraph ) {
     3495  const CoinStaticConflictGraph *cg = (CoinStaticConflictGraph *)cgraph;
     3496  return cg->density();
     3497}
     3498
     3499
     3500CGNeighbors CG_conflictingNodes(Cbc_Model *model, void *cgraph, size_t node) {
     3501  CGNeighbors result;
     3502
     3503#ifdef CBC_THREAD
     3504    pthread_mutex_lock(&model->cbcMutexCG);
     3505#endif
     3506
     3507  if (model->cg_space < Cbc_getNumCols(model)*2) {
     3508    if (model->cg_space) {
     3509      free( model->cg_neighs);
     3510      free(model->cg_iv);
     3511    }
     3512
     3513    model->cg_space = Cbc_getNumCols(model)*2;
     3514
     3515    model->cg_neighs  = (size_t *) xmalloc( sizeof(size_t)*model->cg_space );
     3516    model->cg_iv  = (bool *) xmalloc( sizeof(bool)*model->cg_space );
     3517    memset(model->cg_iv, 0, sizeof(bool)*model->cg_space);
     3518  }
     3519
     3520  const CoinStaticConflictGraph *cg = (CoinStaticConflictGraph *)cgraph;
     3521
     3522  std::pair< size_t, const size_t* > r = cg->conflictingNodes( node, model->cg_neighs, model->cg_iv);
     3523#ifdef CBC_THREAD
     3524    pthread_mutex_unlock(&model->cbcMutexCG);
     3525#endif
     3526
     3527  result.n = r.first;
     3528  result.neigh = r.second;
     3529
     3530  return result;
     3531}
     3532
     3533
     3534
     3535
     3536
    34563537/** @brief Returns column name in OsiSolverInterface object */
    34573538void CBC_LINKAGE
     
    41854266  model->lp_method = LPM_Auto;
    41864267  model->dualp = DP_Auto;
     4268  model->cg_space = 0;
     4269  model->cg_iv = NULL;
     4270  model->cg_neighs = NULL;
    41874271  memset(model->int_param, 0, sizeof(model->int_param) );
    41884272  for ( int i=0 ; (i<N_DBL_PARAMS) ; ++i )
  • trunk/src/Cbc_C_Interface.h

    r3032 r3035  
    14701470Osi_deleteSolver( void *osi );
    14711471
     1472/** @brief Creates (it not yet) the conflict graph  */
     1473CBCSOLVERLIB_EXPORT void CBC_LINKAGE
     1474Osi_checkCGraph( void *osi );
     1475
     1476/** @brief Returns the conflict graph */
     1477CBCSOLVERLIB_EXPORT const void * CBC_LINKAGE
     1478Osi_CGraph( void *osi );
     1479
    14721480/*@}*/
     1481
     1482/** \name Conflict Graph related routines */
     1483
     1484/** @brief Number of nodes in the conflict graph */
     1485CBCSOLVERLIB_EXPORT size_t CBC_LINKAGE
     1486CG_nodes( void *cgraph );
     1487
     1488/** @brief If two nodes are conflicting */
     1489CBCSOLVERLIB_EXPORT char CBC_LINKAGE
     1490CG_conflicting( void *cgraph, int n1, int n2 );
     1491
     1492/** @brief Density of the conflict graph */
     1493CBCSOLVERLIB_EXPORT double CBC_LINKAGE
     1494CG_density( void *cgraph );
     1495
     1496
     1497/** structure to store neighbors of a given node in
     1498 * the conflict graph */
     1499typedef struct {
     1500  size_t n;
     1501  const size_t *neigh;
     1502} CGNeighbors;
     1503
     1504/** @brief Returns all nodes conflicting with a node ]
     1505 *
     1506 * Caution: if you want to keep the pointer to the
     1507 * conflicting node list stored, be sure to copy it,
     1508 * after each call the previous pointer contents
     1509 * may be updated.
     1510 *
     1511 * */
     1512CBCSOLVERLIB_EXPORT CGNeighbors CBC_LINKAGE
     1513CG_conflictingNodes(Cbc_Model *model, void *cgraph, size_t node);
     1514
     1515
     1516/*@}*/
     1517
    14731518
    14741519/** \name Cgl related routines */
Note: See TracChangeset for help on using the changeset viewer.