Commit d0218176 authored by makoto.nishizawa's avatar makoto.nishizawa

applied to new question model

parent 7164ee51
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -DSOFTWARE
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
......@@ -14,6 +14,8 @@ short int block_data[MAXBLOCK+1][5][3]; // ブロックの情報
short int board_data[MAXW][MAXH]; // 盤面情報
short int line_num=0;
void reset_parameters(void){
int i,j,k;
for(i=0;i<MAXBLOCK;i++)
......@@ -59,10 +61,11 @@ void read_problem(void){
nowx=num=0;
gets(str);
for(k=0;;k++){
if(str[k]=='*')
if(str[k]=='0' && num==0)
num=-1;
else if('0'<=str[k]&&str[k]<='9')
num=num*10+str[k]-'0';
if(num>line_num) line_num=num;
else if(str[k]==','){
if(num<0){
num=0;
......
......@@ -30,6 +30,7 @@ extern short int board_data[MAXW][MAXH]; // 盤面情報
// ...
// (0,71),(1,71), ... ,(71,71)
// 基本的には回答フォーマットに沿う形
extern short int line_num;
void reset_parameters(void); // read_problem に内包
void read_problem(void);
......
File added
/* main.c */
/* Last Change: 2019/05/21 (Tue) 14:44:03. */
#include"io.h"
#include"solver.h"
......
File added
all: main.cpp io.c solver.cpp
g++ -o solve main.cpp io.c solver.cpp -std=c++11
all: main.cpp io.c solver.cpp router/router.cpp
g++ -o solve solver.cpp main.cpp io.c router/router.cpp -std=c++11
o: main.o io.o solver.o
g++ -o solve main.o io.o solver.o
......@@ -11,4 +11,4 @@ io.o: io.c
g++ -c io.c
solver.o: solver.cpp
g++ -c solver.cpp
g++ -c solver.cpp -std=c++11
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -DSOFTWARE
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
# Basic router
* A*ベースの配線プログラム
* 入力
* 盤面サイズ(size_x, size_y)
* ライン数(line_num)
* 盤面情報(size_x$`\times`$size_yの盤面に整数を割り当て,自然数: ライン端点,-1: 配線禁止領域, 0: 配線領域)
* 出力
* status(自然数: 配線成功,0: 配線失敗),配線成功時のstatusは総配線長を表す
* 配線結果
* routerに渡す盤面情報,routerから返される配線結果は1次元配列(入力が2次元配列の場合,変換が必要)
* ハードウェア化に備えて余計な型やヘッダファイルを含むが,その辺はご了承願いたい...
### Change log
* 2019.07.16
* 端点の隣接判定に関するバグを修正
* 端点を結ぶパスが存在しないときにプログラムが停止するバグを修正
* 配線成功時のstatusを総配線長に変更
### 関数呼び出し
* 関数routerの呼び出し方法は以下のサンプルコードの通り
* routerの第5引数はシード値で指定は任意(default=12345)
```
short int size_x = 10, size_y = 10;
short int line_num = 6;
short int board[10][10], board_str[100];
/* ここで盤面情報を設定 */
// Transform "board" to "board_str"
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_str[idx] = board[y][x];
}
}
int status = router(size_x, size_y, line_num, board_str, 1234567);
// Transform "board_str" to "board"
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board[y][x] = board_str[idx];
}
}
```
### 必要ファイル
* router.cpp
* router.hpp
* ap_int.h
* etc/ap_fixed_sim.h
* etc/ap_int_sim.h
* etc/ap_private.h
### パラメタ
* router.hpp上部で以下を設定可能
|定数名|説明|
|:---|:---|
|ROUND_LIMIT|引きはがし再配線回数の上限(default: 32768, Max: 65534),小さいほど諦めが早い|
|PRINT_BOARD|配線前と配線後の盤面を表示(コメントアウトで非表示)|
|PRINT_SEARCH|配線の途中経過をすべて表示(コメントアウトで非表示)|
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "router.hpp"
int main(int argc, char *argv[]){
short int size_x = 10, size_y = 10;
short int line_num = 6;
short int board[10][10], board_str[100];
int x, y;
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x ++) {
board[y][x] = 0;
}
}
// Terminal cells (value > 0)
board[0][1] = 1;
board[7][1] = 1;
board[0][3] = 2;
board[8][4] = 2;
board[4][5] = 3;
board[6][5] = 3;
board[4][6] = 4;
board[7][2] = 4;
board[5][4] = 5;
board[6][6] = 5;
board[9][8] = 6;
board[9][9] = 6;
// Routing disenabled cells (value < 0)
board[0][0] = -1;
board[1][7] = -1;
board[1][8] = -1;
board[2][1] = -1;
board[2][7] = -1;
board[2][8] = -1;
board[3][1] = -1;
board[4][1] = -1;
board[5][1] = -1;
// Transform "board" to "board_str"
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_str[idx] = board[y][x];
}
}
/** top function of router **/
// status = 1: OK
// status = 0: NG
int status = router(size_x, size_y, line_num, board_str);
/** top function of router (User can set "seed" value manually when calling this function.) **/
//int status = router(size_x, size_y, line_num, board_str, 1234567);
cout << "Router status: " << status << endl;
// Transform "board_str" to "board"
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board[y][x] = board_str[idx];
}
}
return 0;
}
File added
This diff is collapsed.
#ifndef __ROUTER_HPP__
#define __ROUTER_HPP__
#include <iostream>
#define SOFTWARE
#ifdef SOFTWARE
#include "ap_int.h"
#else
#include <ap_int.h>
#endif
using namespace std;
#define ROUND_LIMIT 32768 // Max=65534(=2^16-2)
#define PRINT_BOARD
//#define PRINT_SEARCH // for router debug
#define MAX_LINES 256
#define MAX_PATH 128
#define MAX_CELLS 16384 // 128x128
#define PQ_BIT 12
#define MAX_PQ 4096
#define PRIO_BIT 16
#define DATA_BIT 16
#define ELEM_BIT 32 // ELEM_BIT = PRIO_BIT + DATA_BIT
#define DATA_MASK 65535 // 0000 FFFF
#define DATA_MAX 65535 // FFFF
#define PRIO_MAX 65535 // FFFF
/** top function (User can set "seed" value manually when calling this function.) **/
int router(short int size_x, short int size_y, short int line_num, short int board_str[], ap_uint<32> seed = 12345);
static ap_uint<32> lfsr;
void lfsr_random_init(ap_uint<32> seed);
ap_uint<32> lfsr_random();
ap_uint<PRIO_BIT> new_weight(ap_uint<16> x);
int search(short int size_x, short int size_y, short int *path_size, ap_uint<DATA_BIT> path[MAX_PATH], ap_uint<DATA_BIT> start, ap_uint<DATA_BIT> goal, ap_uint<PRIO_BIT> w[MAX_CELLS]);
void enqueue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> priority, ap_uint<DATA_BIT> data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
void dequeue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> *ret_priority, ap_uint<DATA_BIT> *ret_data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
#endif /* __ROUTER_HPP__ */
File added
File added
No preview for this file type
This diff is collapsed.
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment