-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_type.h
195 lines (174 loc) · 3.73 KB
/
base_type.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef BASE_TYPE_H
#define BASE_TYPE_H
//specs
#define MAX_DECK_TYPE 4
#define MAX_TRUCK_TYPE 4
#define MAX_BUNDLE 8
#define MAX_MEMBER 120
#define MAX_FREE_JOINT 30
#define MAX_FIXED_JOINT 20
#define MAX_JOINT 50
#define MAX_EQUATION (MAX_JOINT*2)
#define MAX_LOAD 12
//type size
#define SIZE_SIZE 33
#define MATERIAL_SIZE 3
#define SHAPE_SIZE 2
#define MAX_TYPE 198
//physical constants
#define GRAVITY 9.8066
#define DEAD_LOAD_FACTOR 1.25
#define LIVE_LOAD_FACTOR 2.3275
#define PI2 9.8696044
#define COMPRESSION_RESISTANCE_FACTOR 0.9
#define TENSION_RESISTANCE_FACTOR 0.95
#define BUNDLE_COST 1000.
#define JOINT_COST 500.
#define DEADLOADFACTOR 1.25
#define LIVELOADFACTOR 2.3275
//defaults for data structure
#define EMPTY_VALUE -1.
#define INVALID_VALUE 10000000.
//quick hands
#define _FFSLL __builtin_ffsll
//TODO mask can't be 0
#define FFSLLL(mask) (_FFSLL(mask)==0?_FFSLL((mask>>64))+64:_FFSLL(mask))
#define GET_BYTE(p) (*(const guchar*)(p))
#define GET_DOLLAR(p) (*(Dollar*)(p))
#define SQR(a) ((a)*(a))
//TODO double check max_load
#include <stdio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
/**************//**
* basic types
*****************/
//gboolean
typedef gboolean Bool;
/**
* useful for space critical application
*/
//gchar
typedef unsigned char Byte;
/**
* TODO make sure it's 64bit to be capatible with original Java implementation.
*/
typedef double Double;
/**
* money unit
*/
typedef Double Dollar;
/**
* index for relugar use
*/
typedef int Int;
/**
* nth bit is 1 if member n pass the type
* TODO ensure size on various application
*/
typedef __uint128_t TestMask;
/**************//**
* small structs
*****************/
/**
* each byte is divided into 2 parts, each 4 bit is
* a signed integer representing relative coordinate
* to positionHint.
*/
typedef struct {
Byte joints[MAX_FREE_JOINT];
} PositionHintB;
/**
* coordinate of all joints in unit of quarter meter.
*/
typedef struct {
Int xy[MAX_EQUATION];
} PositionHint;
/**
* value of the main table
*/
#define TYPE_HINT_COST_SIZE(memberSize) (sizeof(Dollar)+MAX_BUNDLE*sizeof(Byte)+(memberSize))
typedef struct {
/**
* accurate cost for bridge design.
*/
Dollar cost;
/**
* typeIndex of each bundle, have to be in order
*/
Byte bundle[MAX_BUNDLE];
/**
* bundleIndex for each member.
* MAX_BUNDLE is 8. Only 3 bits are neseccary,
* but whole 8 bits are used for convidience.
*/
Byte member[MAX_MEMBER];
} TypeHintCostB;
/**
* struct for GPU? to use
* WARNING: positionHintB is not contained
*/
typedef struct {
//postionHint sensitive
/**
* testMask for each type worth considering
*/
TestMask typeTestMask[MAX_TYPE];
/**
* length of each member
*/
Double length[MAX_MEMBER];
/**
* cost of each type
* unit: Dollar/meter
*/
Dollar cost[MAX_TYPE];
/**
* actual global index of each type
*/
Byte index[MAX_TYPE];
/**
* number of types worth considering
*/
Int typeSize;
Int memberSize;
/**
* used to speed up optimization
* TODO test speed difference, might not be significant.
*/
Dollar capCost;
//bridgeInfo sensitive
Dollar bundleCost;
Double minLength;
} OptimizeTask;
/**
* store the connection configuration of a member.
* j1,j2 is the
*/
typedef struct {
Int j1,j2;
} MemberLink;
/**
* TODO need perfection
*/
typedef enum {
LOADED,
SOLVED_GOOD,
SOLVED_UNSTABLE,
OPTIMIZED_BETTER,
OPTIMIZED_UNCHANGED,
OPTIMIZED_WORSE,
OPTIMIZED_MAX_BUNDLE,
OPTIMIZED_MAX_COST
} Status;
/**************//**
* big class
*****************/
struct _BridgeInfo;
struct _Manager;
struct _Result;
struct _TaskQueue;
struct _CostTable;
char* print_bytes(gconstpointer p,int size);
#endif