Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kawamura-solver
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
adc2019
kawamura-solver
Commits
ee071c06
Commit
ee071c06
authored
Aug 26, 2019
by
kazushi.kawamura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify python wrapper
parent
ae0027ee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
36 deletions
+138
-36
Makefile.arm
solver_python/Makefile.arm
+14
-0
param.hpp
solver_python/param.hpp
+1
-1
py_wrapper.cpp
solver_python/py_wrapper.cpp
+80
-5
solver.cpp
solver_python/solver.cpp
+38
-26
solver.hpp
solver_python/solver.hpp
+5
-4
No files found.
solver_python/Makefile.arm
0 → 100755
View file @
ee071c06
TARGET
=
sim
OBJS
=
$
(
CPPS:.cpp
=
.o
)
CPPS
=
main.cpp io.cpp solver.cpp tools.cpp
CXX
=
arm-linux-gnueabihf-g++
CXXFLAGS
=
-std
=
c++11
-O3
all
:
$(TARGET)
$(TARGET)
:
$(OBJS)
$(CXX)
-o
$@
$(OBJS)
clean
:
rm
*
.o
rm
$(TARGET)
solver_python/param.hpp
View file @
ee071c06
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#define RI 3
#define RI 3
#define BO 4
#define BO 4
#define SA_O 100
0
#define SA_O 100
#define SA_I 100000
#define SA_I 100000
#define TEMP_S 500
#define TEMP_S 500
#define TEMP_E 0.1
#define TEMP_E 0.1
...
...
solver_python/py_wrapper.cpp
View file @
ee071c06
/// py_wrapper.cpp ///
/// py_wrapper.cpp ///
// #include <Python.h>
// #include <Python.h>
#include "/usr/include/python3.
5
m/Python.h"
#include "/usr/include/python3.
6
m/Python.h"
#include "/usr/include/python3.
5
m/numpy/arrayobject.h"
#include "/usr/include/python3.
6
m/numpy/arrayobject.h"
#include "/usr/include/python3.
5
m/numpy/arrayscalars.h"
#include "/usr/include/python3.
6
m/numpy/arrayscalars.h"
#include <iostream>
#include <iostream>
#include <fstream>
#include <fstream>
...
@@ -199,6 +199,80 @@ static PyObject* check_problem_wrapper(PyObject* self, PyObject* args) {
...
@@ -199,6 +199,80 @@ static PyObject* check_problem_wrapper(PyObject* self, PyObject* args) {
return
dict
;
return
dict
;
}
}
static
PyObject
*
placer_wrapper
(
PyObject
*
self
,
PyObject
*
args
)
{
uint32_t
seed
[
3
];
short
int
W
,
H
,
blocks
,
line_num
;
short
int
block_info
[
MAX_BLOCKS
+
1
][
5
][
3
];
short
int
line_info
[
MAX_LINES
+
1
][
2
][
5
];
PyObject
*
a_seed
;
PyObject
*
a_block_info
;
PyObject
*
a_line_info
;
// PyObject (ndarray, short int, short int, short int, short int, ndarray, ndarray)
if
(
!
PyArg_ParseTuple
(
args
,
"O!hhhhO!O!"
,
&
PyArray_Type
,
&
a_seed
,
&
W
,
&
H
,
&
blocks
,
&
line_num
,
&
PyArray_Type
,
&
a_block_info
,
&
PyArray_Type
,
&
a_line_info
))
{
return
NULL
;
}
seed
[
0
]
=
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
0
);
seed
[
1
]
=
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
1
);
seed
[
2
]
=
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
2
);
for
(
npy_intp
i
=
0
;
i
<
MAX_BLOCKS
+
1
;
i
++
)
{
for
(
npy_intp
j
=
0
;
j
<
5
;
j
++
)
{
for
(
npy_intp
k
=
0
;
k
<
3
;
k
++
)
{
block_info
[
i
][
j
][
k
]
=
*
(
short
int
*
)
PyArray_GETPTR3
(
a_block_info
,
i
,
j
,
k
);
}
}
}
for
(
npy_intp
i
=
0
;
i
<
MAX_LINES
+
1
;
i
++
)
{
for
(
npy_intp
j
=
0
;
j
<
2
;
j
++
)
{
for
(
npy_intp
k
=
0
;
k
<
5
;
k
++
)
{
line_info
[
i
][
j
][
k
]
=
*
(
short
int
*
)
PyArray_GETPTR3
(
a_line_info
,
i
,
j
,
k
);
}
}
}
// block positions on slot matrix
short
int
block_place_global
[
MAX_BLOCKS
+
1
][
2
];
placer
(
seed
,
W
,
H
,
blocks
,
line_num
,
block_info
,
line_info
,
block_place_global
);
// create dictionary
PyObject
*
dict
=
PyDict_New
();
// seed //
PyObject
*
seed_key
=
PyUnicode_FromString
(
"seed"
);
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
0
)
=
seed
[
0
];
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
1
)
=
seed
[
1
];
*
(
uint32_t
*
)
PyArray_GETPTR1
(
a_seed
,
2
)
=
seed
[
2
];
PyDict_SetItem
(
dict
,
seed_key
,
a_seed
);
// block_info //
PyObject
*
block_place_key
=
PyUnicode_FromString
(
"block_place"
);
int
ndim
=
2
;
npy_intp
*
s
=
(
npy_intp
*
)
malloc
(
ndim
*
sizeof
(
npy_intp
));
s
[
0
]
=
MAX_BLOCKS
+
1
;
s
[
1
]
=
2
;
PyObject
*
block_place_list
=
PyArray_SimpleNew
(
ndim
,
s
,
NPY_INT16
);
// ndarray
free
(
s
);
for
(
npy_intp
i
=
0
;
i
<
MAX_BLOCKS
+
1
;
i
++
)
{
*
(
short
int
*
)
PyArray_GETPTR2
(
block_place_list
,
i
,
0
)
=
block_place_global
[
i
][
0
];
*
(
short
int
*
)
PyArray_GETPTR2
(
block_place_list
,
i
,
1
)
=
block_place_global
[
i
][
1
];
}
PyDict_SetItem
(
dict
,
block_place_key
,
block_place_list
);
// PyObject (dictionary)
return
dict
;
}
static
PyObject
*
solver_wrapper
(
PyObject
*
self
,
PyObject
*
args
)
{
static
PyObject
*
solver_wrapper
(
PyObject
*
self
,
PyObject
*
args
)
{
uint32_t
seed
[
3
];
uint32_t
seed
[
3
];
...
@@ -329,7 +403,7 @@ static PyObject* show_result_wrapper(PyObject* self, PyObject* args) {
...
@@ -329,7 +403,7 @@ static PyObject* show_result_wrapper(PyObject* self, PyObject* args) {
}
}
}
}
}
}
for
(
npy_intp
i
=
0
;
i
<
MAX_
BLOCKS
+
1
;
i
++
)
{
for
(
npy_intp
i
=
0
;
i
<
MAX_
CELLS
;
i
++
)
{
opt_result
[
i
]
=
*
(
short
int
*
)
PyArray_GETPTR1
(
a_opt_result
,
i
);
opt_result
[
i
]
=
*
(
short
int
*
)
PyArray_GETPTR1
(
a_opt_result
,
i
);
}
}
...
@@ -366,7 +440,7 @@ static PyObject* output_to_file_wrapper(PyObject* self, PyObject* args) {
...
@@ -366,7 +440,7 @@ static PyObject* output_to_file_wrapper(PyObject* self, PyObject* args) {
}
}
}
}
}
}
for
(
npy_intp
i
=
0
;
i
<
MAX_
BLOCKS
+
1
;
i
++
)
{
for
(
npy_intp
i
=
0
;
i
<
MAX_
CELLS
;
i
++
)
{
opt_result
[
i
]
=
*
(
short
int
*
)
PyArray_GETPTR1
(
a_opt_result
,
i
);
opt_result
[
i
]
=
*
(
short
int
*
)
PyArray_GETPTR1
(
a_opt_result
,
i
);
}
}
...
@@ -385,6 +459,7 @@ static PyMethodDef mySolverMethods[] = {
...
@@ -385,6 +459,7 @@ static PyMethodDef mySolverMethods[] = {
{
"test_func"
,
test_func_wrapper
,
METH_VARARGS
,
"test function"
},
{
"test_func"
,
test_func_wrapper
,
METH_VARARGS
,
"test function"
},
{
"seed_generator"
,
seed_generator_wrapper
,
METH_VARARGS
,
"generate seed values"
},
{
"seed_generator"
,
seed_generator_wrapper
,
METH_VARARGS
,
"generate seed values"
},
{
"check_problem"
,
check_problem_wrapper
,
METH_VARARGS
,
"read problem"
},
{
"check_problem"
,
check_problem_wrapper
,
METH_VARARGS
,
"read problem"
},
{
"placer"
,
placer_wrapper
,
METH_VARARGS
,
"placer"
},
{
"solver"
,
solver_wrapper
,
METH_VARARGS
,
"solver"
},
{
"solver"
,
solver_wrapper
,
METH_VARARGS
,
"solver"
},
{
"show_result"
,
show_result_wrapper
,
METH_VARARGS
,
"show result"
},
{
"show_result"
,
show_result_wrapper
,
METH_VARARGS
,
"show result"
},
{
"output_to_file"
,
output_to_file_wrapper
,
METH_VARARGS
,
"output result to file"
},
{
"output_to_file"
,
output_to_file_wrapper
,
METH_VARARGS
,
"output result to file"
},
...
...
solver_python/solver.cpp
View file @
ee071c06
...
@@ -7,7 +7,7 @@ int solver(uint32_t seed[3], short int W, short int H, short int blocks, short i
...
@@ -7,7 +7,7 @@ int solver(uint32_t seed[3], short int W, short int H, short int blocks, short i
lfsr_random_init
(
seed
[
0
],
seed
[
1
],
seed
[
2
]);
lfsr_random_init
(
seed
[
0
],
seed
[
1
],
seed
[
2
]);
// block positions on slot matrix
// block positions on slot matrix
pair
<
short
int
,
short
int
>
block_place_global
[
MAX_BLOCKS
+
1
];
short
int
block_place_global
[
MAX_BLOCKS
+
1
][
2
];
while
(
1
)
{
while
(
1
)
{
global_placement
(
W
,
H
,
line_num
,
blocks
,
block_info
,
line_info
,
block_place_global
);
global_placement
(
W
,
H
,
line_num
,
blocks
,
block_info
,
line_info
,
block_place_global
);
...
@@ -19,6 +19,18 @@ int solver(uint32_t seed[3], short int W, short int H, short int blocks, short i
...
@@ -19,6 +19,18 @@ int solver(uint32_t seed[3], short int W, short int H, short int blocks, short i
return
0
;
return
0
;
}
}
int
placer
(
uint32_t
seed
[
3
],
short
int
W
,
short
int
H
,
short
int
blocks
,
short
int
line_num
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
])
{
lfsr_random_init
(
seed
[
0
],
seed
[
1
],
seed
[
2
]);
global_placement
(
W
,
H
,
line_num
,
blocks
,
block_info
,
line_info
,
block_place_global
);
seed
[
0
]
=
lfsr
;
seed
[
1
]
=
lfsr_x
;
seed
[
2
]
=
lfsr_y
;
return
0
;
}
void
lfsr_random_init
(
uint32_t
seed
,
uint32_t
seed_x
,
uint32_t
seed_y
)
{
void
lfsr_random_init
(
uint32_t
seed
,
uint32_t
seed_x
,
uint32_t
seed_y
)
{
lfsr
=
seed
;
lfsr
=
seed
;
lfsr_x
=
seed_x
;
lfsr_x
=
seed_x
;
...
@@ -59,7 +71,7 @@ uint32_t lfsr_y_random() {
...
@@ -59,7 +71,7 @@ uint32_t lfsr_y_random() {
return
lfsr_y
;
return
lfsr_y
;
}
}
float
calcPlaceCost
(
short
int
line_num
,
short
int
line_info
[][
2
][
5
],
pair
<
short
int
,
short
int
>
block_place_global
[
])
{
float
calcPlaceCost
(
short
int
line_num
,
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
])
{
short
int
block1
,
block2
;
// block idx
short
int
block1
,
block2
;
// block idx
short
int
x1
,
y1
;
// 1st block
short
int
x1
,
y1
;
// 1st block
...
@@ -77,10 +89,10 @@ float calcPlaceCost(short int line_num, short int line_info[][2][5], pair<short
...
@@ -77,10 +89,10 @@ float calcPlaceCost(short int line_num, short int line_info[][2][5], pair<short
for
(
int
l
=
1
;
l
<=
line_num
;
l
++
)
{
// Calc cost
for
(
int
l
=
1
;
l
<=
line_num
;
l
++
)
{
// Calc cost
block1
=
line_info
[
l
][
0
][
0
];
// 1st block including line#L
block1
=
line_info
[
l
][
0
][
0
];
// 1st block including line#L
block2
=
line_info
[
l
][
1
][
0
];
// 2nd block including line#L
block2
=
line_info
[
l
][
1
][
0
];
// 2nd block including line#L
x1
=
block_place_global
[
block1
]
.
first
;
x1
=
block_place_global
[
block1
]
[
0
]
;
y1
=
block_place_global
[
block1
]
.
second
;
y1
=
block_place_global
[
block1
]
[
1
]
;
x2
=
block_place_global
[
block2
]
.
first
;
x2
=
block_place_global
[
block2
]
[
0
]
;
y2
=
block_place_global
[
block2
]
.
second
;
y2
=
block_place_global
[
block2
]
[
1
]
;
delta_x
=
x1
-
x2
;
delta_x
=
x1
-
x2
;
delta_y
=
y1
-
y2
;
delta_y
=
y1
-
y2
;
dist_x
=
abs
(
delta_x
);
dist_x
=
abs
(
delta_x
);
...
@@ -112,7 +124,7 @@ float calcPlaceCost(short int line_num, short int line_info[][2][5], pair<short
...
@@ -112,7 +124,7 @@ float calcPlaceCost(short int line_num, short int line_info[][2][5], pair<short
return
cost
;
return
cost
;
}
}
void
global_placement
(
short
int
W
,
short
int
H
,
short
int
line_num
,
short
int
blocks
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
pair
<
short
int
,
short
int
>
block_place_global
[
])
{
void
global_placement
(
short
int
W
,
short
int
H
,
short
int
line_num
,
short
int
blocks
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
])
{
cout
<<
"== Global placement =="
<<
endl
;
cout
<<
"== Global placement =="
<<
endl
;
short
int
sx_sum
=
0
,
sy_sum
=
0
;
short
int
sx_sum
=
0
,
sy_sum
=
0
;
...
@@ -136,9 +148,9 @@ void global_placement(short int W, short int H, short int line_num, short int bl
...
@@ -136,9 +148,9 @@ void global_placement(short int W, short int H, short int line_num, short int bl
for
(
short
int
q
=
0
;
q
<=
max_y
;
q
++
)
{
for
(
short
int
q
=
0
;
q
<=
max_y
;
q
++
)
{
for
(
short
int
p
=
0
;
p
<=
max_x
;
p
++
)
{
for
(
short
int
p
=
0
;
p
<=
max_x
;
p
++
)
{
if
(
i
<=
blocks
)
{
if
(
i
<=
blocks
)
{
block_place_global
[
i
]
=
make_pair
(
p
,
q
);
block_place_global
[
i
][
0
]
=
p
;
block_place_global
[
i
][
1
]
=
q
;
global_slot
[
q
][
p
]
=
i
;
global_slot
[
q
][
p
]
=
i
;
//cout << "Block#" << i << ": (" << block_place_global[i].first << ", " << block_place_global[i].second << ")" << endl;
i
++
;
i
++
;
}
}
else
{
else
{
...
@@ -164,28 +176,28 @@ void global_placement(short int W, short int H, short int line_num, short int bl
...
@@ -164,28 +176,28 @@ void global_placement(short int W, short int H, short int line_num, short int bl
// i_x, i_y, j_x, j_y
// i_x, i_y, j_x, j_y
for
(
int
counter_in
=
0
;
counter_in
<
SA_I
;
counter_in
++
)
{
for
(
int
counter_in
=
0
;
counter_in
<
SA_I
;
counter_in
++
)
{
short
int
trgt_i
=
lfsr_random
()
%
blocks
+
1
;
short
int
trgt_i
=
lfsr_random
()
%
blocks
+
1
;
short
int
i_x
=
block_place_global
[
trgt_i
]
.
first
;
short
int
i_x
=
block_place_global
[
trgt_i
]
[
0
]
;
short
int
i_y
=
block_place_global
[
trgt_i
]
.
second
;
short
int
i_y
=
block_place_global
[
trgt_i
]
[
1
]
;
short
int
j_x
=
lfsr_x_random
()
%
SLOT_MAX_SIZE
;
short
int
j_x
=
lfsr_x_random
()
%
SLOT_MAX_SIZE
;
short
int
j_y
=
lfsr_y_random
()
%
SLOT_MAX_SIZE
;
short
int
j_y
=
lfsr_y_random
()
%
SLOT_MAX_SIZE
;
if
(
j_x
>
max_x
||
j_y
>
max_y
)
continue
;
if
(
j_x
>
max_x
||
j_y
>
max_y
)
continue
;
short
int
trgt_j
=
global_slot
[
j_y
][
j_x
];
// slot -> block
short
int
trgt_j
=
global_slot
[
j_y
][
j_x
];
// slot -> block
block_place_global
[
trgt_i
]
.
first
=
j_x
;
block_place_global
[
trgt_i
]
[
0
]
=
j_x
;
block_place_global
[
trgt_i
]
.
second
=
j_y
;
block_place_global
[
trgt_i
]
[
1
]
=
j_y
;
global_slot
[
j_y
][
j_x
]
=
trgt_i
;
global_slot
[
j_y
][
j_x
]
=
trgt_i
;
block_place_global
[
trgt_j
]
.
first
=
i_x
;
block_place_global
[
trgt_j
]
[
0
]
=
i_x
;
block_place_global
[
trgt_j
]
.
second
=
i_y
;
block_place_global
[
trgt_j
]
[
1
]
=
i_y
;
global_slot
[
i_y
][
i_x
]
=
trgt_j
;
global_slot
[
i_y
][
i_x
]
=
trgt_j
;
float
new_cost
=
calcPlaceCost
(
line_num
,
line_info
,
block_place_global
);
float
new_cost
=
calcPlaceCost
(
line_num
,
line_info
,
block_place_global
);
if
(
new_cost
>
cost
&&
(
float
)
lfsr_random
()
/
LFSR_RAND_MAX
>
expf
(
-
(
new_cost
-
cost
)
/
temperature
))
{
if
(
new_cost
>
cost
&&
(
float
)
lfsr_random
()
/
LFSR_RAND_MAX
>
expf
(
-
(
new_cost
-
cost
)
/
temperature
))
{
block_place_global
[
trgt_i
]
.
first
=
i_x
;
block_place_global
[
trgt_i
]
[
0
]
=
i_x
;
block_place_global
[
trgt_i
]
.
second
=
i_y
;
block_place_global
[
trgt_i
]
[
1
]
=
i_y
;
global_slot
[
i_y
][
i_x
]
=
trgt_i
;
global_slot
[
i_y
][
i_x
]
=
trgt_i
;
block_place_global
[
trgt_j
]
.
first
=
j_x
;
block_place_global
[
trgt_j
]
[
0
]
=
j_x
;
block_place_global
[
trgt_j
]
.
second
=
j_y
;
block_place_global
[
trgt_j
]
[
1
]
=
j_y
;
global_slot
[
j_y
][
j_x
]
=
trgt_j
;
global_slot
[
j_y
][
j_x
]
=
trgt_j
;
}
}
else
if
(
new_cost
!=
cost
)
{
else
if
(
new_cost
!=
cost
)
{
...
@@ -215,7 +227,7 @@ pair<short int,short int> sub_pair(pair<short int,short int> x, pair<short int,s
...
@@ -215,7 +227,7 @@ pair<short int,short int> sub_pair(pair<short int,short int> x, pair<short int,s
return
make_pair
(
x
.
first
-
y
.
first
,
x
.
second
-
y
.
second
);
return
make_pair
(
x
.
first
-
y
.
first
,
x
.
second
-
y
.
second
);
}
}
bool
local_placement_with_routing_1
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
pair
<
short
int
,
short
int
>
block_place_global
[
],
short
int
opt_result
[])
{
bool
local_placement_with_routing_1
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
short
int
block_place_global
[][
2
],
short
int
opt_result
[])
{
short
int
wi
,
hi
;
// board size (w, h)
short
int
wi
,
hi
;
// board size (w, h)
...
@@ -234,8 +246,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
...
@@ -234,8 +246,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
// load a placement result
// load a placement result
short
int
min_x
=
SLOT_MAX_SIZE
,
min_y
=
SLOT_MAX_SIZE
,
max_x
=
0
,
max_y
=
0
;
short
int
min_x
=
SLOT_MAX_SIZE
,
min_y
=
SLOT_MAX_SIZE
,
max_x
=
0
,
max_y
=
0
;
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
short
int
p
=
block_place_global
[
i
]
.
first
;
short
int
p
=
block_place_global
[
i
]
[
0
]
;
short
int
q
=
block_place_global
[
i
]
.
second
;
short
int
q
=
block_place_global
[
i
]
[
1
]
;
if
(
p
<
min_x
)
{
min_x
=
p
;
}
if
(
p
<
min_x
)
{
min_x
=
p
;
}
if
(
q
<
min_y
)
{
min_y
=
q
;
}
if
(
q
<
min_y
)
{
min_y
=
q
;
}
if
(
p
>
max_x
)
{
max_x
=
p
;
}
if
(
p
>
max_x
)
{
max_x
=
p
;
}
...
@@ -250,8 +262,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
...
@@ -250,8 +262,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
short
int
sx
=
block_info
[
i
][
0
][
0
];
short
int
sx
=
block_info
[
i
][
0
][
0
];
short
int
sy
=
block_info
[
i
][
0
][
1
];
short
int
sy
=
block_info
[
i
][
0
][
1
];
short
int
p
=
block_place_global
[
i
]
.
first
;
short
int
p
=
block_place_global
[
i
]
[
0
]
;
short
int
q
=
block_place_global
[
i
]
.
second
;
short
int
q
=
block_place_global
[
i
]
[
1
]
;
if
(
sx
>
slot_w
[
p
])
{
slot_w
[
p
]
=
sx
;
}
if
(
sx
>
slot_w
[
p
])
{
slot_w
[
p
]
=
sx
;
}
if
(
sy
>
slot_h
[
q
])
{
slot_h
[
q
]
=
sy
;
}
if
(
sy
>
slot_h
[
q
])
{
slot_h
[
q
]
=
sy
;
}
}
}
...
@@ -273,8 +285,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
...
@@ -273,8 +285,8 @@ bool local_placement_with_routing_1(short int line_num, short int blocks, short
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
)
{
short
int
sx
=
block_info
[
i
][
0
][
0
];
short
int
sx
=
block_info
[
i
][
0
][
0
];
short
int
sy
=
block_info
[
i
][
0
][
1
];
short
int
sy
=
block_info
[
i
][
0
][
1
];
short
int
p
=
block_place_global
[
i
]
.
first
;
short
int
p
=
block_place_global
[
i
]
[
0
]
;
short
int
q
=
block_place_global
[
i
]
.
second
;
short
int
q
=
block_place_global
[
i
]
[
1
]
;
block_place_basis
[
i
]
=
make_pair
(
slot_w_t
[
p
],
slot_h_t
[
q
]);
block_place_basis
[
i
]
=
make_pair
(
slot_w_t
[
p
],
slot_h_t
[
q
]);
block_place_slack
[
i
][
0
]
=
slot_w
[
p
]
-
sx
;
block_place_slack
[
i
][
0
]
=
slot_w
[
p
]
-
sx
;
block_place_slack
[
i
][
1
]
=
slot_h
[
q
]
-
sy
;
block_place_slack
[
i
][
1
]
=
slot_h
[
q
]
-
sy
;
...
...
solver_python/solver.hpp
View file @
ee071c06
#ifndef __SOLVER_HPP__
#ifndef __SOLVER_HPP__
#define __SOLVER_HPP__
#define __SOLVER_HPP__
#include "/usr/include/python3.
5
m/Python.h"
#include "/usr/include/python3.
6
m/Python.h"
#include <iostream>
#include <iostream>
#include <math.h>
#include <math.h>
...
@@ -12,15 +12,16 @@
...
@@ -12,15 +12,16 @@
using
namespace
std
;
using
namespace
std
;
int
solver
(
uint32_t
seed
[
3
],
short
int
W
,
short
int
H
,
short
int
blocks
,
short
int
line_num
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
*
pwi
,
short
int
*
phi
,
short
int
opt_result
[]);
int
solver
(
uint32_t
seed
[
3
],
short
int
W
,
short
int
H
,
short
int
blocks
,
short
int
line_num
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
*
pwi
,
short
int
*
phi
,
short
int
opt_result
[]);
int
placer
(
uint32_t
seed
[
3
],
short
int
W
,
short
int
H
,
short
int
blocks
,
short
int
line_num
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
]);
void
lfsr_random_init
(
uint32_t
seed
,
uint32_t
seed_x
,
uint32_t
seed_y
);
void
lfsr_random_init
(
uint32_t
seed
,
uint32_t
seed_x
,
uint32_t
seed_y
);
uint32_t
lfsr_random
();
uint32_t
lfsr_random
();
uint32_t
lfsr_x_random
();
uint32_t
lfsr_x_random
();
uint32_t
lfsr_y_random
();
uint32_t
lfsr_y_random
();
void
global_placement
(
short
int
W
,
short
int
H
,
short
int
line_num
,
short
int
blocks
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
pair
<
short
int
,
short
int
>
block_place_global
[
]);
void
global_placement
(
short
int
W
,
short
int
H
,
short
int
line_num
,
short
int
blocks
,
short
int
block_info
[][
5
][
3
],
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
]);
float
calcPlaceCost
(
short
int
line_num
,
short
int
line_info
[][
2
][
5
],
pair
<
short
int
,
short
int
>
block_place_global
[
]);
float
calcPlaceCost
(
short
int
line_num
,
short
int
line_info
[][
2
][
5
],
short
int
block_place_global
[][
2
]);
bool
local_placement_with_routing_1
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
pair
<
short
int
,
short
int
>
block_place_global
[
],
short
int
opt_result
[]);
bool
local_placement_with_routing_1
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
short
int
block_place_global
[][
2
],
short
int
opt_result
[]);
bool
local_placement_with_routing_2
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
short
int
opt_result
[]);
bool
local_placement_with_routing_2
(
short
int
line_num
,
short
int
blocks
,
short
int
*
pwi
,
short
int
*
phi
,
short
int
block_info
[][
5
][
3
],
short
int
opt_result
[]);
pair
<
short
int
,
short
int
>
add_pair
(
pair
<
short
int
,
short
int
>
x
,
pair
<
short
int
,
short
int
>
y
);
pair
<
short
int
,
short
int
>
add_pair
(
pair
<
short
int
,
short
int
>
x
,
pair
<
short
int
,
short
int
>
y
);
pair
<
short
int
,
short
int
>
sub_pair
(
pair
<
short
int
,
short
int
>
x
,
pair
<
short
int
,
short
int
>
y
);
pair
<
short
int
,
short
int
>
sub_pair
(
pair
<
short
int
,
short
int
>
x
,
pair
<
short
int
,
short
int
>
y
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment