Commit 579749b1 authored by  tawada's avatar tawada

Update

parent b7744d9a
problem x y z lines occupation avelength solved made by length corner parallel length (resolved) corner (resolved) parallel (resolved)
1 24 24 4 60 41.796875 16.05 o 0 952 164 216
2 15 15 2 12 48 18 o 1 222 41 156
3 20 20 8 29 11.25 12.413793 o 4 375 55 8
4 72 72 8 8 2.083333 108 O 3 606 15 0
5 8 8 4 20 53.515625 6.85 o 5 130 26 15
6 48 36 8 101 8.738426 11.960396 o 2 1224 247 140
7 72 72 8 8 2.517361 130.5 O 0 587 16 0
8 70 70 8 999 26.007653 10.205205 X 0
9 15 15 2 47 60.222222 5.765957 o 0 262 80 19
10 23 12 6 49 39.673913 13.408163 o 0 610 124 127
11 8 4 8 17 50.78125 7.647059 o 5 128 24 0
12 36 19 4 71 34.027778 13.112676 o 2 828 126 302
13 72 72 8 52 1.31414 10.480769 o 3 200 19 0
14 10 10 2 22 72.5 6.590909 o 0 131 48 5
15 60 36 8 102 9.675926 16.392157 O 4 1666 198 41
16 15 15 4 81 46.555556 5.17284 o 0 411 98 10
17 50 50 4 825 50.64 6.138182 X 0
18 20 35 8 22 8.5 21.636364 o 4 472 51 19
19 36 24 1 96 90.162037 8.114583 x 1 780 156 90
20 30 30 3 210 47.962963 6.166667 O 0 1248 342 51
21 72 72 5 73 22.071759 78.369863 X 0 5472 141 5318
22 72 72 2 2 3.587963 186 o 2 288 5 0
23 40 40 3 123 99.75 38.926829 X 0 4798 621 4054
24 60 60 4 999 48.923611 7.052052 X 0
25 40 40 4 212 99.8125 30.132075 X 0 6400 416 5574
26 15 15 3 56 46.222222 5.571429 o 0 323 79 30
27 72 72 8 8 2.194252 113.75 O 3 616 34 35
28 3 3 3 6 100 4.5 o 0 26 10 0
29 72 72 1 85 100 60.988235 x 0 5184 468 4666
30 72 72 1 160 100 32.4 x 0 5184 629 4443
31 16 20 5 272 100 5.882353 x 1 1600 336 1050
32 40 40 3 425 53.416667 6.032941 O 0 2591 673 146
33 40 40 2 150 99.875 21.306667 X 0 3200 356 2730
34 40 40 3 80 99.75 59.85 X 0 4800 1560 3120
TARGET = solver
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -Wall -O3
all: $(TARGET)
run: $(TARGET)
./$(TARGET) ../dataQsample.txt ../dataAsample.txt -rp
test:$(TARGET)
for i in `seq 1 34`; do ./$(TARGET) `printf "../../ADC2017_Q_A/all/Q/Q%02d.txt" $$i` `printf "../../ADC2017_Q_A/all/A/A%02d.txt" $$i` -o `printf "RESOLV_A%02d.txt" $$i` -r; done
$(TARGET): $(OBJS)
$(CXX) -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
# checker & resolver
* 開発言語: C++
* 機能: 1.チェッカー,2.コスト計算,3.コスト削減のための再ルーティング
## 入出力
* 問題ファイル
* 解答ファイル(再ルーティング前)
* 解答ファイル(再ルーティング後) ※任意
## 1.チェッカー
* 解答ファイル(再ルーティング前)が解答ルールを満たしているか確認
* branch error: ラインの分岐が存在
* floating error: 端点に接続しない数字が存在
## 2.コスト計算
* 要オプション(-c)
* 線長の合計と線が曲った回数を導出
## 3.再ルーティング
* 要オプション(-r)
* 1ラインずつ引きはがして再ルーティング
* 曲がる回数が少なくなるようなルーティングを選択
/*******************************************************/
/** クラス定義 **/
/*******************************************************/
#ifndef __BOARD_HPP__
#define __BOARD_HPP__
// 各種最大値
// ライン数は 72*72*8/2
#define MAX_BOXES 72
#define MAX_LAYER 8
#define MAX_LINES 20736
// ボードクラス
class Board{
public:
Board(int _x,int _y,int _z,int _ln){
size_x = _x;
size_y = _y;
size_z = _z;
line_num = _ln;
for(int z=0;z<size_z;z++){
for(int y=0;y<size_y;y++){
for(int x=0;x<size_x;x++){
Box* box;
box = new Box(x,y,z);
boxes[z][y][x] = box;
}
}
}
for(int i=1;i<=line_num;i++){
Line* line;
line = new Line(i);
lines[i] = line;
}
}
~Board(){
// デストラクタ(要メモリ解放)
}
int getSizeX(){return size_x;}
int getSizeY(){return size_y;}
int getSizeZ(){return size_z;}
int getLineNum(){return line_num;}
Box* box(int x,int y,int z){return boxes[z][y][x];} // マスの取得
Line* line(int idx){return lines[idx];} // ラインの取得
private:
int size_x; // X方向サイズ
int size_y; // Y方向サイズ
int size_z; // Z方向サイズ
int line_num; // ライン数
Box* boxes[MAX_LAYER][MAX_BOXES][MAX_BOXES]; // マスの集合
Line* lines[MAX_LINES]; // ラインの集合
};
#endif
/*******************************************************/
/** クラス定義 **/
/*******************************************************/
#ifndef __BOX_HPP__
#define __BOX_HPP__
// マスクラス
class Box{
public:
enum BoxType {TYPE_NULL,TYPE_NUMBER,TYPE_BLANK};
Box(int _x,int _y,int _z):type(TYPE_NULL),index(NOT_USE),has_line(false){x=_x;y=_y;z=_z;}
~Box();
int getIndex(){return index;}
void setIndex(int _index){index=_index;}
bool isTypeNumber() const{return (type==TYPE_NUMBER);}
void setTypeNumber(){type=TYPE_NUMBER;}
bool isTypeBlank() const{return (type==TYPE_BLANK);}
void setTypeBlank(){type=TYPE_BLANK;}
int getX(){return x;}
int getY(){return y;}
int getZ(){return z;}
bool checkLine() const{return has_line;}
void setHasLine(){has_line=true;}
void resetHasLine(){has_line=false;}
private:
BoxType type; // 種類 (数字,空白)
int index; // 数字 (空白マスは-1)
int x, y, z; // 座標
bool has_line; // ラインの有無
};
#endif
/*******************************************************/
/** クラス定義 **/
/*******************************************************/
#ifndef __LINE_HPP__
#define __LINE_HPP__
// ラインクラス
class Line{
public:
Line(int _index):x_0(NOT_USE),y_0(NOT_USE),z_0(NOT_USE),x_1(NOT_USE),y_1(NOT_USE),z_1(NOT_USE){index=_index;track.clear();}
~Line();
int getIndex(){return index;}
void setSourcePort(int x,int y,int z){x_0=x;y_0=y;z_0=z;}
int getSourceX(){return x_0;}
int getSourceY(){return y_0;}
int getSourceZ(){return z_0;}
void setSinkPort(int x,int y,int z){x_1=x;y_1=y;z_1=z;}
int getSinkX(){return x_1;}
int getSinkY(){return y_1;}
int getSinkZ(){return z_1;}
// スタートとゴールが隣接していないか?
void setHasLine(bool _has_line){has_line = _has_line;}
bool getHasLine(){return has_line;}
int getLineLength(){return track.size();}
vector<Point>* getTrack(){return &track;}
void pushPointToTrack(Point p){track.push_back(p);}
void clearTrack(){track.clear();}
private:
int index; // ライン番号
int x_0, y_0, z_0; // ソースポート
int x_1, y_1, z_1; // シンクポート
bool has_line; // スタートとゴールが隣接していないか?
vector<Point> track;
};
#endif
This diff is collapsed.
#ifndef _MAIN_HPP_
#define _MAIN_HPP_
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <assert.h>
#include <getopt.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
#define NOT_USE -1
// Inter-Box
#define NORTH 1
#define EAST 2
#define SOUTH 3
#define WEST 4
#define UP 5
#define DOWN 6
struct Point{
int x;
int y;
int z;
};
#include "line.hpp"
#include "box.hpp"
#include "board.hpp"
#define ML 3 // コストの計算(配線長)
#define BT 3 // コストの計算(曲がり回数)
#define PL 1 // コストの計算(周辺ノード)
struct Search{
int x;
int y;
int z;
int d; // 方向
};
struct Direction{
// 方向
bool n; // 北
bool s; // 南
bool e; // 東
bool w; // 西
bool u; // 上
bool d; // 下
// ひとつ前の方向
int c_n;
int c_s;
int c_e;
int c_w;
int c_u;
int c_d;
};
struct IntraBox{
int cost;
Direction d;
};
/*******************************************************/
/** グローバル関数定義 **/
/*******************************************************/
void initialize(char* filename);
void readSolution(char* filename, bool print_option);
#endif /*_MAIN_HPP_*/
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/
#include <stdio.h>
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
static unsigned long mt[N]; /* the array for the state vector */
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
/* initializes mt[N] with a seed */
void init_genrand(unsigned long s)
{
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
void init_by_array(unsigned long init_key[], int key_length)
{
int i, j, k;
init_genrand(19650218UL);
i=1; j=0;
k = (N>key_length ? N : key_length);
for (; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
+ init_key[j] + j; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++; j++;
if (i>=N) { mt[0] = mt[N-1]; i=1; }
if (j>=key_length) j=0;
}
for (k=N-1; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
- i; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++;
if (i>=N) { mt[0] = mt[N-1]; i=1; }
}
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
unsigned long genrand_int32(void)
{
unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= N) { /* generate N words at one time */
int kk;
if (mti == N+1) /* if init_genrand() has not been called, */
init_genrand(5489UL); /* a default initial seed is used */
for (kk=0;kk<N-M;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
mti = 0;
}
y = mt[mti++];
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
}
/* generates a random number on [0,0x7fffffff]-interval */
long genrand_int31(void)
{
return (long)(genrand_int32()>>1);
}
/* generates a random number on [0,1]-real-interval */
double genrand_real1(void)
{
return genrand_int32()*(1.0/4294967295.0);
/* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
double genrand_real2(void)
{
return genrand_int32()*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
double genrand_real3(void)
{
return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
double genrand_res53(void)
{
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
return(a*67108864.0+b)*(1.0/9007199254740992.0);
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
This diff is collapsed.
/*******************************************************/
/** ルーティングに関する関数 **/
/*******************************************************/
#ifndef __ROUTE_HPP__
#define __ROUTE_HPP__
// ルーティング
bool routing(int trgt_line_id);
bool isInserted(int x,int y,int z);
int cost_parallel(int trgt_line_id, int x, int y, int z);
// 記録と抹消
void recordLine(int trgt_line_id);
void deleteLine(int trgt_line_id);
#endif
#include "main.hpp"
#include "utils.hpp"
extern Board* board;
// 2桁の整数をアルファベットに変換
char changeIntToChar(int n){
if (0 <= n && n < 10) {
return (char)(n + '0');
} else if (n <= 35) {
return (char)(n - 10 + 'A');
}
return '#';
}
// コストを計算
void calcCost(){
int total_length = 0;
int total_corner = 0;
int total_cost;
for(int i=1;i<=board->getLineNum();i++){
Line* trgt_line = board->line(i);
vector<Point>* trgt_track = trgt_line->getTrack();
total_length += (int)(trgt_track->size()) - 1;
for(int j=1;j<(int)(trgt_track->size())-1;j++){
Point p0 = (*trgt_track)[j-1];
Point p1 = (*trgt_track)[j];
Point p2 = (*trgt_track)[j+1];
if( ((p1.x-p0.x) != (p2.x-p1.x)) || ((p1.y-p0.y) != (p2.y-p1.y)) || ((p1.z-p0.z) != (p2.z-p1.z)) ){
total_corner++;
}
}
}
total_cost = total_length + total_corner;
cout << endl;
cout << "Length: " << total_length << endl;
cout << "Corner: " << total_corner << endl;
cout << "Total cost: " << total_cost << endl;
cout << endl;
}
// 問題盤を表示
void printBoard(){
cout << endl;
cout << "PROBLEM" << endl;
cout << "=======" << endl;
for(int z=0;z<board->getSizeZ();z++){
cout << "LAYER " << z+1 << endl;
for(int y=0;y<board->getSizeY();y++){
for(int x=0;x<board->getSizeX();x++){
Box* trgt_box = board->box(x,y,z);
if(trgt_box->isTypeBlank()){
cout << "[.]";
}
else if(trgt_box->isTypeNumber()){
int trgt_num = trgt_box->getIndex();
cout << "[" << changeIntToChar(trgt_num) << "]";
}
else{
cout << "(-)";
}
}
cout << endl;
}
cout << endl;
}
}
// ラインナンバーから色をマッピング (Foreground colors)
// 31m ~ 37m まで 7色
string getcolorescape_fore(int n) {
int color = ((n - 1) % 7) + 31;
stringstream ss;
ss << color;
string p = "\033[";
string s = "m";
return p + ss.str() + s;
}
// ラインナンバーから色をマッピング (Background colors)
// 41m ~ 47m まで 7色
string getcolorescape(int n) {
int color = ((n - 1) % 7) + 41;
stringstream ss;
ss << color;
string p = "\033[";
string s = "m";
return p + ss.str() + s;
}
// 正解を表示(正解表示は数字2桁)
void printSolution(){
map<int,map<int,map<int,int> > > for_print;
for(int z=0;z<board->getSizeZ();z++){
for(int y=0;y<board->getSizeY();y++){
for(int x=0;x<board->getSizeX();x++){
for_print[z][y][x] = -1;
}
}
}
for(int i=1;i<=board->getLineNum();i++){
Line* trgt_line = board->line(i);
vector<Point>* trgt_track = trgt_line->getTrack();
for(int j=0;j<(int)(trgt_track->size());j++){
Point p = (*trgt_track)[j];
int point_x = p.x;
int point_y = p.y;
int point_z = p.z;
for_print[point_z][point_y][point_x] = i;
}
}
cout << endl;
cout << "SOLUTION" << endl;
cout << "========" << endl;
for(int z=0;z<board->getSizeZ();z++){
cout << "LAYER " << z+1 << endl;
for(int y=0;y<board->getSizeY();y++){
for(int x=0;x<board->getSizeX();x++){
int n = for_print[z][y][x];
if(n < 0){
// 線が引かれていないマス:"00"表示
cout << "\033[37m00\033[0m";
}else{
Box* trgt_box = board->box(x,y,z);
if(trgt_box->isTypeNumber()){
// 線が引かれているマス [端点] (2桁表示)
cout << getcolorescape_fore(n) << setfill('0') << setw(2) << n << "\033[0m";
}else{
// 線が引かれているマス [非端点] (2桁表示)
cout << getcolorescape(n) << setfill('0') << setw(2) << n << "\033[0m";
}
}
if(x != board->getSizeX()-1) cout << " ";
}
cout << endl;
}
cout << endl;
}
}
// 正解を表示 (ファイル出力)
void printSolutionToFile(char *filename) {
map<int,map<int,map<int,int> > > for_print;
for(int z=0;z<board->getSizeZ();z++){
for(int y=0;y<board->getSizeY();y++){
for(int x=0;x<board->getSizeX();x++){
for_print[z][y][x] = -1;
}
}
}
for(int i=1;i<=board->getLineNum();i++){
Line* trgt_line = board->line(i);
vector<Point>* trgt_track = trgt_line->getTrack();
for(int j=0;j<(int)(trgt_track->size());j++){
Point p = (*trgt_track)[j];
int point_x = p.x;
int point_y = p.y;
int point_z = p.z;
for_print[point_z][point_y][point_x] = i;
}
}
ofstream ofs(filename);
ofs << "SIZE " << board->getSizeX() << "X" << board->getSizeY() << "X" << board->getSizeZ() << endl;
for(int z=0;z<board->getSizeZ();z++){
ofs << "LAYER " << z+1 << endl;
for(int y=0;y<board->getSizeY();y++){
for(int x=0;x<board->getSizeX();x++){
if(for_print[z][y][x] < 0){
// 線が引かれていないマス:"0"表示
ofs << "0";
}
else{
// その他
ofs << for_print[z][y][x];
}
if(x!=(board->getSizeX()-1)){
ofs << ",";
}
}
ofs << endl;
}
}
}
// ================================ //
// メルセンヌ・ツイスタ
// ================================ //
#include "mt19937ar.c"
void mt_init_genrand(unsigned long s) {
init_genrand(s);
}
// AからBの範囲の整数の乱数が欲しいとき
// 参考 http://www.sat.t.u-tokyo.ac.jp/~omi/random_variables_generation.html
unsigned long mt_genrand_int32(int a, int b) {
return genrand_int32() % (b - a + 1) + a;
}
#ifndef __UTILS_HPP__
#define __UTILS_HPP__
// 問題盤を表示
void printBoard();
// コストを計算
void calcCost();
// 正解を表示 (正解表示は数字2桁)
void printSolution();
// 正解を表示 (ファイル出力)
void printSolutionToFile(char *filename);
// メルセンヌ・ツイスタ
void mt_init_genrand(unsigned long s);
unsigned long mt_genrand_int32(int a, int b);
#endif
......@@ -7,7 +7,7 @@ PYTHON = python3
.PHONY:run all test clean
run:
$(PYTHON) $(TARGET).py -i dataAsample.txt
$(PYTHON) $(TARGET).py -i ../dataAsample.txt -o ../dataAoutput.txt
all: $(TARGET)
......
......@@ -38,10 +38,14 @@ class MAP:
y_index += 1
self.n_line = int(np.amax(self.map))
self.line = np.zeros((self.n_line,2,3))
self.line = self.line.astype(np.int8)
for x,y,z in itertools.product(\
range(self.X), range(self.Y), range(self.Z)):
neighbours = self.neighbour([x,y,z])
neighbours = self.isregular(neighbours)
index = int(self.map[x][y][z]-1)
if index==-1:
continue
num = self.countV(index+1, neighbours)
if num == 1:
if list(self.line[index][0]) == [0,0,0]:
......@@ -52,9 +56,9 @@ class MAP:
self.line[index][1][0] = x
self.line[index][1][1] = y
self.line[index][1][2] = z
self.line = self.line.astype(np.int8)
self.map = self.map.astype(np.int8)
def countV(self, value, point_list):
"""座標リストpoint_list内の座標(x,y,z)のself.mapの値(ラインのインデックス)がvalueと等しいものの個数を数えます"""
c = 0
......@@ -137,7 +141,7 @@ class MAP:
for y in range(self.Y):
for x in range(self.X-1):
str.append("%02d," % self.map[x][y][zm])
str.append("%d\n" % self.map[self.X-1][y][zm])
str.append("%02d\n" % self.map[self.X-1][y][zm])
return "".join(str)
def save(self):
......@@ -212,7 +216,7 @@ class MAP:
def neighbour(self, point):
""" 与えられた座標をX,Y,Z方向に1移動させ, それら座標のリストを返す """
dlist=np.array([[0,0,-1], [0,0,1], [0,-1,0], [0,1,0], [-1,0,0], [1,0,0]])
nlist=point+dlist
nlist=np.array(point)+dlist
return nlist
def addLine(self, maxlength):
......@@ -252,16 +256,22 @@ class MAP:
cost += 1
return cost
def checkLine(self, n_line):
"""デバッグ用, 指定の線が繋がっているかを確認"""
def optLine(self, n_line):
MAX=72*72*8
MAX_COST = 9999999
n_index = n_line-1
dlist=np.array([[0,0,-1], [0,0,1], [0,-1,0], [0,1,0], [-1,0,0], [1,0,0]])
#既存の線を削除 (端点も削除するので注意)
self.map[self.map==n_line]=0
q=[]
#コスト, 座標, ラインが引かれた方向
heapq.heappush(q, (0, list(self.line[n_line-1][0]), [0,0,0]))
cost_map = np.zeros((72,72,8,3,3,3)).astype(np.int32)
cost_map = np.zeros((72,72,8,3,3,3))
for i in itertools.product(range(72),range(72),range(8),range(3),range(3),range(3)):
cost_map[i] = MAX_COST
......@@ -271,6 +281,8 @@ class MAP:
while True:
if q == []:
exit(1)
print("error")
break
(priority, point, direction) = heapq.heappop(q)
if list(point) == list(self.line[n_line-1][1]):
......@@ -308,7 +320,6 @@ class MAP:
while True:
self.map[tuple(focus_p)]=n_line
next_p = focus_p - focus_d
direction_min = focus_d
cost_min = cost_map[tuple(np.append(next_p, focus_d).astype(np.int8))]
for d in dlist:
......@@ -322,7 +333,13 @@ class MAP:
break
self.map[tuple(focus_p)]=n_line
t = tuple(self.line[n_line-1][0])
if self.map[t] != n_line:
print("error")
t = tuple(self.line[n_line-1][1])
if self.map[t] != n_line:
print("error")
def optimize(self):
#ライン数の10倍の回数だけ「線の引き剥がし・再配線」を繰り返す.
iteration = min(len(self.line)*10,200)
......@@ -331,16 +348,20 @@ class MAP:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='NLGenerator')
parser = argparse.ArgumentParser(description='Resolve')
parser.add_argument('--input', '-i', default=None, type=str,
help='Input file')
parser.add_argument('--output', '-o', default=None, type=str,
help='Output file')
parser.add_argument('--no_print', '-n', default=None, type=str,
help='print')
args = parser.parse_args()
np.random.seed(3)
m=MAP(args.input)
m.printA()
if args.no_print is not None:
m.printA()
m.optimize()
m.printA()
if args.no_print is not None:
m.printA()
m.saveA(args.output)
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