Scippy

SCIP

Solving Constraint Integer Programs

grphbase.c File Reference

Detailed Description

includes several methodes for Steiner problem graphs

Author
Thorsten Koch
Daniel Rehfeldt

This file contains several basic methods to process Steiner problem graphs. A graph can not be reduced in terms of edge or node size, but edges can be marked as EAT_FREE (to not be used anymore) and nodes may have degree one. The method 'graph_pack()' can be used to build a new graph that discards these nodes and edges.

Definition in file grphbase.c.

#include "scip/misc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "portab.h"
#include "misc_stp.h"
#include "grph.h"

Go to the source code of this file.

Functions

SCIP_RETCODE graph_init (SCIP *scip, GRAPH **g, int ksize, int esize, int layers, int flags)
 
SCIP_RETCODE graph_init_history (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE graph_resize (SCIP *scip, GRAPH *g, int ksize, int esize, int layers)
 
static int getNodeNumber (int grid_dim, int shiftcoord, int *ncoords, int *currcoord)
 
static void compEdgesObst (int coord, int grid_dim, int nobstacles, int *ncoords, int *currcoord, int *edgecosts, int *gridedgecount, int **coords, int **gridedges, int **obst_coords, char *inobstacle)
 
static void compEdges (int coord, int grid_dim, int *ncoords, int *currcoord, int *edgecosts, int *gridedgecount, int **coords, int **gridedges)
 
SCIP_RETCODE graph_obstgrid_create (SCIP *scip, GRAPH **gridgraph, int **coords, int **obst_coords, int nterms, int grid_dim, int nobstacles, int scale_order)
 
SCIP_RETCODE graph_grid_create (SCIP *scip, GRAPH **gridgraph, int **coords, int nterms, int grid_dim, int scale_order)
 
SCIP_RETCODE graph_grid_coordinates (SCIP *scip, int **coords, int **nodecoords, int *ncoords, int node, int grid_dim)
 
SCIP_RETCODE graph_prize_transform (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE graph_PcSapCopy (SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Real *offset)
 
SCIP_RETCODE graph_PcToSap (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE graph_rootprize_transform (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE graph_maxweight_transform (SCIP *scip, GRAPH *graph, SCIP_Real *maxweights)
 
SCIP_RETCODE graph_MwcsToSap (SCIP *scip, GRAPH *graph, SCIP_Real *maxweights)
 
void graph_free (SCIP *scip, GRAPH *p, SCIP_Bool final)
 
SCIP_RETCODE graph_copy (SCIP *scip, GRAPH *orgraph, GRAPH **copygraph)
 
void graph_flags (GRAPH *p, int flags)
 
void graph_show (const GRAPH *p)
 
void graph_ident (const GRAPH *p)
 
void graph_knot_add (GRAPH *p, int term)
 
void graph_knot_chg (GRAPH *p, int node, int term)
 
SCIP_RETCODE graph_knot_contract (SCIP *scip, GRAPH *p, int t, int s)
 
void prize_subtract (SCIP *scip, GRAPH *g, SCIP_Real cost, int i)
 
SCIP_RETCODE graph_knot_contractpc (SCIP *scip, GRAPH *g, int t, int s, int i)
 
int graph_edge_redirect (SCIP *scip, GRAPH *g, int eki, int k, int j, SCIP_Real cost)
 
SCIP_RETCODE graph_edge_reinsert (SCIP *scip, GRAPH *g, int e1, int k1, int k2, SCIP_Real cost, IDX *ancestors0, IDX *ancestors1, IDX *revancestors0, IDX *revancestors1)
 
void graph_edge_add (SCIP *scip, GRAPH *g, int tail, int head, SCIP_Real cost1, SCIP_Real cost2)
 
static void edge_remove (GRAPH *g, int e)
 
void graph_edge_del (SCIP *scip, GRAPH *g, int e, SCIP_Bool freeancestors)
 
void graph_edge_hide (GRAPH *g, int e)
 
void graph_uncover (GRAPH *g)
 
SCIP_RETCODE pcgraphorg (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE pcgraphtrans (SCIP *scip, GRAPH *graph)
 
SCIP_RETCODE graph_pack (SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Bool verbose)
 
void graph_trail (const GRAPH *p, int i)
 
int graph_valid (const GRAPH *p)
 
SCIP_Bool graph_sol_valid (SCIP *scip, const GRAPH *graph, int *result)
 
char graph_valid2 (SCIP *scip, const GRAPH *graph, SCIP_Real *cost)
 

Function Documentation

static void compEdges ( int  coord,
int  grid_dim,
int *  ncoords,
int *  currcoord,
int *  edgecosts,
int *  gridedgecount,
int **  coords,
int **  gridedges 
)
static

used by graph_grid_create

Definition at line 336 of file grphbase.c.

References getNodeNumber().

Referenced by graph_grid_create().

static void compEdgesObst ( int  coord,
int  grid_dim,
int  nobstacles,
int *  ncoords,
int *  currcoord,
int *  edgecosts,
int *  gridedgecount,
int **  coords,
int **  gridedges,
int **  obst_coords,
char *  inobstacle 
)
static

used by graph_obstgrid_create

Definition at line 266 of file grphbase.c.

References FALSE, getNodeNumber(), and TRUE.

Referenced by graph_obstgrid_create().

static void edge_remove ( GRAPH g,
int  e 
)
inlinestatic
Parameters
gthe graph
ethe edge to be removed

Definition at line 1928 of file grphbase.c.

References GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, GRAPH::oeat, GRAPH::outbeg, and GRAPH::tail.

Referenced by graph_edge_del(), and graph_edge_hide().

static int getNodeNumber ( int  grid_dim,
int  shiftcoord,
int *  ncoords,
int *  currcoord 
)
static

used by graph_grid_create

Definition at line 237 of file grphbase.c.

Referenced by compEdges(), compEdgesObst(), graph_grid_create(), and graph_obstgrid_create().

void graph_edge_add ( SCIP *  scip,
GRAPH g,
int  tail,
int  head,
SCIP_Real  cost1,
SCIP_Real  cost2 
)

add a new edge to the graph

Parameters
scipSCIP data structure
gthe graph
tailtail of the new edge
headhead of the new edge
cost1tail to head cost
cost2head to tail cost

Definition at line 1879 of file grphbase.c.

References GRAPH::cost, GRAPH::edges, GRAPH::esize, GRAPH::grad, GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, GRAPH::oeat, GRAPH::outbeg, GRAPH::tail, and UNKNOWN.

Referenced by graph_grid_create(), graph_obstgrid_create(), graph_pack(), graph_PcSapCopy(), graph_PcToSap(), graph_prize_transform(), graph_rootprize_transform(), and pcgraphtrans().

void graph_edge_hide ( GRAPH g,
int  e 
)

hide edge

Parameters
gthe graph
ethe edge

Definition at line 2015 of file grphbase.c.

References EAT_FREE, EAT_HIDE, edge_remove(), GRAPH::grad, GRAPH::head, GRAPH::ieat, GRAPH::oeat, and GRAPH::tail.

int graph_edge_redirect ( SCIP *  scip,
GRAPH g,
int  eki,
int  k,
int  j,
SCIP_Real  cost 
)
Parameters
scipSCIP data structure
gthe graph
ekithe edge
knew tail
jnew head
costnew cost

Definition at line 1783 of file grphbase.c.

References GRAPH::cost, EAT_FREE, EAT_LAST, Edge_anti, FALSE, GRAPH::grad, graph_edge_del(), GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, GRAPH::oeat, GRAPH::outbeg, and GRAPH::tail.

Referenced by bd3_reduction(), degree_test_pc(), graph_edge_reinsert(), graph_PcSapCopy(), and traverseChain().

SCIP_RETCODE graph_edge_reinsert ( SCIP *  scip,
GRAPH g,
int  e1,
int  k1,
int  k2,
SCIP_Real  cost,
IDX ancestors0,
IDX ancestors1,
IDX revancestors0,
IDX revancestors1 
)

reinsert an edge to replace two other edges

Parameters
scipSCIP data structure
gthe graph
e1edge to reinsert
k1tail
k2head
costedgecost
ancestors0ancestors of first edge
ancestors1ancestors of second edge
revancestors0reverse ancestors of first edge
revancestors1reverse ancestors of first edge

Definition at line 1846 of file grphbase.c.

References GRAPH::ancestors, Edge_anti, graph_edge_redirect(), SCIPintListNodeAppendCopy(), and SCIPintListNodeFree().

Referenced by bd3_reduction(), bdr_reduction(), bound_reduce(), and da_reduce().

void graph_flags ( GRAPH p,
int  flags 
)

set flags

Parameters
pthe graph
flagsnew flags

Definition at line 1307 of file grphbase.c.

References GRAPH::flags.

Referenced by graph_load().

SCIP_RETCODE graph_grid_coordinates ( SCIP *  scip,
int **  coords,
int **  nodecoords,
int *  ncoords,
int  node,
int  grid_dim 
)

computes coordinates of node 'node'

Parameters
scipSCIP data structure
coordscoordinates
nodecoordscoordinates of the node (to be computed)
ncoordsarray with number of coordinate
nodethe node
grid_dimproblem dimension

Definition at line 691 of file grphbase.c.

Referenced by SCIPprobdataWriteSolution().

SCIP_RETCODE graph_grid_create ( SCIP *  scip,
GRAPH **  gridgraph,
int **  coords,
int  nterms,
int  grid_dim,
int  scale_order 
)

creates a graph out of a given grid

Parameters
scipSCIP data structure
gridgraphthe grid graph to be constructed
coordscoordinates
ntermsnumber of terminals
grid_dimproblem dimension
scale_orderscale order

Definition at line 535 of file grphbase.c.

References compEdges(), getNodeNumber(), graph_edge_add(), graph_init(), graph_knot_add(), graph_knot_chg(), GRAPH::grid_coordinates, GRAPH::grid_dim, GRAPH::grid_ncoords, GRAPH::source, STP_GRID, and GRAPH::stp_type.

Referenced by graph_load().

void graph_ident ( const GRAPH p)
SCIP_RETCODE graph_init_history ( SCIP *  scip,
GRAPH graph 
)

initialize data structures required to keep track of reductions

Parameters
scipSCIP data structure
graphgraph

Definition at line 128 of file grphbase.c.

References GRAPH::ancestors, GRAPH::edges, GRAPH::head, GRAPH::knots, GRAPH::orghead, GRAPH::orgtail, GRAPH::pcancestors, STP_MAX_NODE_WEIGHT, STP_PRIZE_COLLECTING, STP_ROOTED_PRIZE_COLLECTING, GRAPH::stp_type, and GRAPH::tail.

Referenced by daPc_reduce(), and reduce().

void graph_knot_chg ( GRAPH p,
int  node,
int  term 
)
SCIP_RETCODE graph_knot_contract ( SCIP *  scip,
GRAPH p,
int  t,
int  s 
)
SCIP_RETCODE graph_knot_contractpc ( SCIP *  scip,
GRAPH g,
int  t,
int  s,
int  i 
)

contract an edge of (rooted) prize-collecting Steiner tree problem

Parameters
scipSCIP data structure
gthe graph
ttail node to be contracted
shead node to be contracted
iterminal to add offset to

Definition at line 1679 of file grphbase.c.

References GRAPH::ancestors, GRAPH::cost, EAT_LAST, GRAPH::grad, graph_edge_del(), graph_knot_chg(), graph_knot_contract(), GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, Is_pterm, Is_term, GRAPH::mark, GRAPH::oeat, GRAPH::outbeg, GRAPH::pcancestors, GRAPH::prize, prize_subtract(), SCIPintListNodeAppendCopy(), SCIPintListNodeFree(), GRAPH::source, STP_MAX_NODE_WEIGHT, GRAPH::stp_type, GRAPH::tail, GRAPH::term, and TRUE.

Referenced by degree_test_mw(), degree_test_pc(), nv_reduction(), nv_reductionAdv(), sl_reduction(), and trydg1edgepc().

SCIP_RETCODE graph_maxweight_transform ( SCIP *  scip,
GRAPH graph,
SCIP_Real *  maxweights 
)

alters the graph for MWCS problems

Parameters
scipSCIP data structure
graphthe graph
maxweightsarray containing the weight of each node

Definition at line 1020 of file grphbase.c.

References GRAPH::cost, EAT_LAST, graph_knot_chg(), graph_prize_transform(), GRAPH::ieat, GRAPH::inpbeg, Is_term, GRAPH::knots, GRAPH::prize, STP_MAX_NODE_WEIGHT, GRAPH::stp_type, GRAPH::term, and GRAPH::terms.

Referenced by graph_load().

SCIP_RETCODE graph_MwcsToSap ( SCIP *  scip,
GRAPH graph,
SCIP_Real *  maxweights 
)

tansforms an MWCSP to an SAP

Parameters
scipSCIP data structure
graphthe graph
maxweightsarray containing the weight of each node

Definition at line 1079 of file grphbase.c.

References GRAPH::cost, EAT_LAST, graph_knot_chg(), graph_PcToSap(), GRAPH::ieat, GRAPH::inpbeg, Is_term, GRAPH::knots, GRAPH::prize, STP_MAX_NODE_WEIGHT, GRAPH::stp_type, GRAPH::term, and GRAPH::terms.

Referenced by graph_load().

SCIP_RETCODE graph_obstgrid_create ( SCIP *  scip,
GRAPH **  gridgraph,
int **  coords,
int **  obst_coords,
int  nterms,
int  grid_dim,
int  nobstacles,
int  scale_order 
)

creates a graph out of a given grid

Parameters
scipSCIP data structure
gridgraphthe (obstacle) grid graph to be constructed
coordscoordinates of all points
obst_coordscoordinates of obstacles
ntermsnumber of terminals
grid_dimdimension of the problem
nobstaclesnumber of obstacles
scale_orderscale factor

Definition at line 374 of file grphbase.c.

References compEdgesObst(), FALSE, getNodeNumber(), graph_edge_add(), graph_init(), graph_knot_add(), graph_knot_chg(), graph_pack(), GRAPH::grid_coordinates, GRAPH::grid_dim, GRAPH::grid_ncoords, GRAPH::source, STP_OBSTACLES_GRID, GRAPH::stp_type, and TRUE.

Referenced by graph_load().

SCIP_RETCODE graph_PcSapCopy ( SCIP *  scip,
GRAPH graph,
GRAPH **  newgraph,
SCIP_Real *  offset 
)

alters the graph for prize collecting problems

Parameters
scipSCIP data structure
graphthe graph
newgraphthe new graph
offsetoffset

Definition at line 792 of file grphbase.c.

References GRAPH::cost, EAT_LAST, GRAPH::edges, GRAPH::esize, FARAWAY, flipedge, graph_copy(), graph_edge_add(), graph_edge_redirect(), graph_knot_add(), graph_resize(), Is_pterm, Is_term, GRAPH::knots, GRAPH::ksize, GRAPH::prize, GRAPH::source, STP_DIRECTED, GRAPH::stp_type, GRAPH::term, and GRAPH::terms.

Referenced by daPc_reduce(), and SCIPdualAscentPcStp().

SCIP_RETCODE graph_PcToSap ( SCIP *  scip,
GRAPH graph 
)
SCIP_RETCODE graph_prize_transform ( SCIP *  scip,
GRAPH graph 
)
SCIP_RETCODE graph_resize ( SCIP *  scip,
GRAPH g,
int  ksize,
int  esize,
int  layers 
)

enlarge the graph

Parameters
scipSCIP data structure
ggraph to be resized
ksizenew node slots
esizenew edge slots
layerslayers (set to -1 by default)

Definition at line 186 of file grphbase.c.

References GRAPH::cost, GRAPH::edges, GRAPH::esize, GRAPH::grad, GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, GRAPH::knots, GRAPH::ksize, GRAPH::layers, GRAPH::locals, GRAPH::mark, GRAPH::oeat, GRAPH::outbeg, GRAPH::source, GRAPH::tail, and GRAPH::term.

Referenced by graph_PcSapCopy(), graph_PcToSap(), graph_prize_transform(), and graph_rootprize_transform().

SCIP_RETCODE graph_rootprize_transform ( SCIP *  scip,
GRAPH graph 
)

alters the graph for rooted prize collecting problems

Parameters
scipSCIP data structure
graphthe graph

Definition at line 955 of file grphbase.c.

References GRAPH::edges, GRAPH::esize, FARAWAY, graph_edge_add(), graph_knot_add(), graph_knot_chg(), graph_resize(), Is_term, GRAPH::knots, GRAPH::ksize, GRAPH::norgmodeledges, GRAPH::norgmodelknots, GRAPH::prize, GRAPH::source, STP_ROOTED_PRIZE_COLLECTING, GRAPH::stp_type, GRAPH::term, and GRAPH::terms.

Referenced by graph_load().

void graph_show ( const GRAPH p)
SCIP_Bool graph_sol_valid ( SCIP *  scip,
const GRAPH graph,
int *  result 
)

verifies whether a given primal solution is feasible

Parameters
scipSCIP data structure
graphgraph data structure
resultsolution array, indicating whether an edge is in the solution

Definition at line 2639 of file grphbase.c.

References CONNECT, EAT_LAST, FALSE, GRAPH::head, Is_term, GRAPH::knots, GRAPH::oeat, GRAPH::outbeg, GRAPH::source, GRAPH::term, GRAPH::terms, and TRUE.

Referenced by SCIP_DECL_HEUREXEC(), and SCIPheurPrunePCSteinerTree().

void graph_trail ( const GRAPH p,
int  i 
)

traverse the graph

Parameters
pthe new graph
inode to start from

Definition at line 2510 of file grphbase.c.

References EAT_LAST, GRAPH::head, GRAPH::mark, GRAPH::oeat, GRAPH::outbeg, and TRUE.

Referenced by graph_valid(), and level0().

void graph_uncover ( GRAPH g)

reinsert all hidden edges

Parameters
gthe graph

Definition at line 2058 of file grphbase.c.

References EAT_HIDE, GRAPH::edges, GRAPH::grad, GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, GRAPH::oeat, GRAPH::outbeg, and GRAPH::tail.

char graph_valid2 ( SCIP *  scip,
const GRAPH graph,
SCIP_Real *  cost 
)
SCIP_RETCODE pcgraphorg ( SCIP *  scip,
GRAPH graph 
)

mark terminals and switch terminal property to original terminals

Parameters
scipSCIP data structure
graphthe graph

Definition at line 2104 of file grphbase.c.

References FALSE, GRAPH::grad, graph_knot_chg(), Is_pterm, Is_term, GRAPH::knots, GRAPH::mark, GRAPH::source, STP_ROOTED_PRIZE_COLLECTING, GRAPH::stp_type, GRAPH::term, and TRUE.

Referenced by bound_reduce(), da_reduce(), daPc_reduce(), reduceMwcs(), and reducePc().

void prize_subtract ( SCIP *  scip,
GRAPH g,
SCIP_Real  cost,
int  i 
)

subtract a given sum from the prize of a terminal

Parameters
scipSCIP data structure
gthe graph
costcost to be subtracted
ithe terminal

Definition at line 1637 of file grphbase.c.

References GRAPH::cost, EAT_LAST, GRAPH::head, GRAPH::ieat, GRAPH::inpbeg, Is_pterm, GRAPH::mark, GRAPH::oeat, GRAPH::outbeg, GRAPH::prize, GRAPH::source, STP_MAX_NODE_WEIGHT, STP_ROOTED_PRIZE_COLLECTING, GRAPH::stp_type, GRAPH::tail, and GRAPH::term.

Referenced by graph_knot_contractpc().