Labyrinth benchmakr
[IRC.git] / Robust / src / Benchmarks / SingleTM / Labyrinth / \
1 /* =============================================================================
2  *
3  * Router.java
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006.  All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  * 
15  * ------------------------------------------------------------------------
16  * 
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  * 
19  * ------------------------------------------------------------------------
20  * 
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  * 
23  * ------------------------------------------------------------------------
24  * 
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  * 
28  * ------------------------------------------------------------------------
29  * 
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  * 
33  * ------------------------------------------------------------------------
34  * 
35  * Unless otherwise noted, the following license applies to STAMP files:
36  * 
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  * 
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  * 
44  *     * Redistributions of source code must retain the above copyright
45  *       notice, this list of conditions and the following disclaimer.
46  * 
47  *     * Redistributions in binary form must reproduce the above copyright
48  *       notice, this list of conditions and the following disclaimer in
49  *       the documentation and/or other materials provided with the
50  *       distribution.
51  * 
52  *     * Neither the name of Stanford University nor the names of its
53  *       contributors may be used to endorse or promote products derived
54  *       from this software without specific prior written permission.
55  * 
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70
71
72 typedef struct router_solve_arg {
73     router_t* routerPtr;
74     maze_t* mazePtr;
75     list_t* pathVectorListPtr;
76 } router_solve_arg_t;
77
78 public class Router {
79     int xCost;
80     int yCost;
81     int zCost;
82     int bendCost;
83     
84     public class Solve_Arg {
85         Router routerPtr;
86         Maze mazePtr;
87         List_t pathVectorListPtr;
88     }
89
90     enum {
91         MOMENTUM_ZERO = 0,
92         MOMENTUM_POSX = 1,
93         MOMENTUM_POSY = 2,
94         MOMENTUM_POSZ = 3,
95         MOMENTUM_NEGX = 4,
96         MOMENTUM_NEGY = 5,
97         MOMENTUM_NEGZ = 6
98     } Momentum_t;
99
100     private class Point {
101         int x;
102         int y;
103         int z;
104         int value;
105         Momentum_t momentum;
106         
107         public Point(int x,int y, int z,int value, Momentum_t m) {
108             this.x = x;
109             this.y = y;
110             this.z = z;
111             this.value = value;
112             momentum = m;
113         }
114     }
115
116     Point MOVE_POSX = new Point(1,0,0,0,MOMENTUM_POSX);
117     Point MOVE_POSY = new Point(0,1,0,0,MOMENTUM_POSY);
118     Point MOVE_POSZ = new Point(0,0,1,0,MOMENTUM_POSZ);
119     Point MOVE_NEGX = new Point(-1,0,0,0,MOMENTUM_NEGX);
120     Point MOVE_NEGY = new Point(0,-1,0,0,MOMENTUM_NEGY);
121     Point MOVE_NEGZ = new Point(0,0,-1,0,MOMENTUM_NEGZ);
122
123
124 /* =============================================================================
125  * router_alloc
126  * =============================================================================
127  * router_t* router_alloc (long xCost, long yCost, long zCost, long bendCost);
128  */
129     public static Router alloc(int xCost,int yCost,int zCost,int bendCost)
130     {
131         Router routerPtr = new Router();
132
133         if(routerPtr != null) {
134             routerPtr.xCost = xCost;
135             routerPtr.yCost = yCost;
136             routerPtr.zCost = zCost;
137             routerPtr.bendCost = bendCost;
138         }
139
140         return routerPtr;    
141     }
142
143
144
145
146 /* =============================================================================
147  * router_free
148  * =============================================================================
149  * void router_free (router_t* routerPtr);
150  */
151     public static void free(Router routerPtr) 
152     {
153         routerPtr = null;
154     }
155
156
157     
158 /* ============================================================================
159  * traceToNeighbor
160  * ============================================================================
161  */
162     private void traceToNeighbor(Grid myGridPtr,
163                                  Point currPtr,
164                                  Point movePtr,
165                                  boolean useMomentum,
166                                  int bendCost,
167                                  Point nextPtr)
168     {
169         int x = currPtr.x + movePtr.x;
170         int y = currPtr.y + movePtr.y;
171         int z = currPtr.z + movePtr.z;
172
173         if (myGridPtr.isPointValid(x,y,z) &&
174                 !myGridPtr.isPointEmpty(x,y,z) &&
175                 !myGridPtr.isPointFull(x,y,z))
176         {
177             int value = myGridPtr.getPoint(x,y,z);
178             int b = 0;
179             
180             if (useMomentum && (currPtr.momentum != movePtr.momentum)) {
181                 b = bendCost;
182             }
183             if ((value + b) <= nextPtr.value) { /* '=' favors neighbors over current */
184                 nextPtr.x = x;
185                 nextPtr.y = y;
186                 nextPtr.z = z;
187                 nextPtr.value = value;
188                 nextPtr.momentum = movePtr.momentum;
189             }
190         }
191     }
192
193     
194 /* =============================================================================
195  * router_solve
196  * =============================================================================
197  * void router_solve (void* argPtr);
198  */
199     public void solve(Object argPtr) 
200     {
201         Barrior
202     }
203
204
205 }
206
207 /* =============================================================================
208  *
209  * End of router.h
210  *
211  * =============================================================================
212  */