Scippy

SCIP

Solving Constraint Integer Programs

stptest_da.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file stptest_da.c
17  * @brief tests for Steiner tree dual-ascent
18  * @author Daniel Rehfeldt
19  *
20  * This file implements unit tests for Steiner tree dual-ascent methods.
21  *
22  * A list of all interface methods can be found in stptest.h.
23  *
24  */
25 
26 //#define SCIP_DEBUG
27 
28 #include <stdio.h>
29 #include <assert.h>
30 #include "stptest.h"
31 #include "graph.h"
32 #include "dualascent.h"
33 #include "portab.h"
34 
35 
36 
37 /** tests that PC DA paths works */
38 static
40  SCIP* scip /**< SCIP data structure */
41 )
42 {
43  GRAPH* graph;
44  GRAPH* transgraph;
45  SCIP_Real* redcosts;
46  const int nnodes_org = 3;
47  const int nedges_org = 6;
48  SCIP_Real obj;
49  SCIP_Real offset = 0.0;
50 
51  SCIP_CALL( graph_init(scip, &graph, nnodes_org, nedges_org, 1) );
52 
53  for( int i = 0; i < nnodes_org; i++ )
55 
56  graph->source = 0;
57 
58  graph_knot_chg(graph, 0, STP_TERM);
59  graph_knot_chg(graph, 2, STP_TERM);
60 
61  graph_edge_addBi(scip, graph, 0, 1, 4.0); // 0,1
62  graph_edge_addBi(scip, graph, 0, 2, 2.0); // 2,3
63  graph_edge_addBi(scip, graph, 1, 2, 0.9);
64 
65  graph_pc_initPrizes(scip, graph, nnodes_org);
66  graph->prize[0] = 2.1; /* the pseudo root */
67  graph->prize[1] = 0.0;
68  graph->prize[2] = 1.9;
69 
71  SCIP_CALL( graph_transPcGetSap(scip, graph, &transgraph, &offset) );
72  SCIP_CALL(SCIPallocMemoryArray(scip, &redcosts, transgraph->edges));
73 
74  SCIP_CALL( dualascent_pathsPcMw(scip, transgraph, redcosts, &obj, NULL) );
75 
76  STPTEST_ASSERT(EQ(redcosts[0], 2.9));
77  STPTEST_ASSERT(EQ(redcosts[1], 1.9));
78  STPTEST_ASSERT(EQ(redcosts[2], 0.1));
79  STPTEST_ASSERT(EQ(redcosts[3], 0.0));
80 
81  graph_free(scip, &transgraph, TRUE);
82  stptest_graphTearDown(scip, graph);
83  SCIPfreeMemoryArray(scip, &redcosts);
84 
85  return SCIP_OKAY;
86 }
87 
88 
89 /** tests DA paths methods */
91  SCIP* scip /**< SCIP data structure */
92 )
93 {
94 
96 
97  printf("DA paths test: all ok \n");
98 
99  return SCIP_OKAY;
100 }
void graph_knot_chg(GRAPH *, int, int)
Definition: graph_node.c:86
#define STPTEST_ASSERT(cond)
Definition: stptest.h:63
int source
Definition: graphdefs.h:195
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:71
void graph_edge_addBi(SCIP *, GRAPH *, int, int, double)
#define SCIPallocMemoryArray(scip, ptr, num)
Definition: scip_mem.h:55
void graph_free(SCIP *, GRAPH **, SCIP_Bool)
Definition: graph_base.c:796
Includes dual-ascent for classic Steiner tree and some variants.
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
includes various files containing graph methods used for Steiner tree problems
SCIP_RETCODE graph_transPcGetSap(SCIP *, GRAPH *, GRAPH **, SCIP_Real *)
Definition: graph_trans.c:931
#define STP_TERM_NONE
Definition: graphdefs.h:62
SCIP_RETCODE graph_pc_initPrizes(SCIP *, GRAPH *, int)
Definition: graph_pcbase.c:741
SCIP_Real * prize
Definition: graphdefs.h:210
void graph_knot_add(GRAPH *, int)
Definition: graph_node.c:64
#define NULL
Definition: lpi_spx1.cpp:155
#define EQ(a, b)
Definition: portab.h:79
#define SCIP_CALL(x)
Definition: def.h:384
static SCIP_RETCODE testDaPathsPcMw3EdgesWorks(SCIP *scip)
Definition: stptest_da.c:39
void stptest_graphTearDown(SCIP *, GRAPH *)
#define STP_TERM
Definition: graphdefs.h:61
Portable definitions.
includes various testing methods for Steiner tree problems
#define SCIP_Real
Definition: def.h:177
int edges
Definition: graphdefs.h:219
SCIP_RETCODE graph_init(SCIP *, GRAPH **, int, int, int)
Definition: graph_base.c:607
SCIP_RETCODE stptest_graphSetUpPcExtended(SCIP *, GRAPH *, int *, int *)
SCIP_RETCODE stptest_dapaths(SCIP *scip)
Definition: stptest_da.c:90
SCIP_RETCODE dualascent_pathsPcMw(SCIP *scip, const GRAPH *transgraph, SCIP_Real *RESTRICT redcost, SCIP_Real *objval, const int *result)
Definition: dualascent.c:1780