Skip to content

Commit

Permalink
Merge branch 'hotfix#2'
Browse files Browse the repository at this point in the history
  • Loading branch information
knewjade committed Jun 6, 2020
2 parents 7d3c0b9 + cb3b4f5 commit 85b4766
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 47 deletions.
10 changes: 9 additions & 1 deletion docs/contents/path/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- 次の2種類の結果を列挙して出力
+ ミノの接着場所が異なるパターンを列挙 (unique)
+ あるパフェパターンに対して、同じようなミノ順をカバーできるパターンが他にあるとき、片方をカットした手順を列挙 (minimal)
- ※ 厳密なすべてのパターンを網羅する最小の組み合わせではありませんのでご注意下さい
- ※ 厳密にすべてのパターンを網羅する最小の組み合わせではありませんのでご注意下さい


基本コマンド
Expand Down Expand Up @@ -69,6 +69,7 @@ short long default
``-k`` ``--key`` none
``-s`` ``--split`` no
``-L`` ``--max-layer`` 2
``-so`` ``--specified-only`` yes
``-r`` ``--reserved`` false
``-d`` ``--drop`` soft
``-th`` ``--threads`` -1
Expand Down Expand Up @@ -169,6 +170,13 @@ formatオプションに csv を選択したとき、さらに出力する項目
* 2: unique, minimal の両方


``-so``, ``--specified-only`` [default: yes]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

minimalの絞り込みにおいて、パターンの重複をチェックするとき、そのパターンを入力パターン内に限定するならyesを指定。
noの場合、解自体から抽出したパターンをもとに、重複をチェックします。


``-r``, ``--reserved`` [default: false]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/entry/path/HaveSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.util.Set;

public interface HaveSet<T> {
Set<T> getSet();
Set<T> getSet(boolean specified_only);
}
15 changes: 8 additions & 7 deletions src/main/java/entry/path/PathCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ List<PathPair> run(Field field, SizedBit sizedBit) throws ExecutionException, In
// 譜面の作成
String fumen = fumenParser.parse(operationsToUrl, field, maxClearLine);

long numOfValidSpecifiedPatterns = getNumOfValidSpecifiedPatterns(field, operations, maxClearLine);
HashSet<LongPieces> validSpecifiedPatterns = getValidSpecifiedPatterns(field, operations, maxClearLine);

return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(operationsToUrl), validPieces, numOfValidSpecifiedPatterns);
return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(operationsToUrl), validPieces, validSpecifiedPatterns);
})
.filter(pathPair -> pathPair != PathPair.EMPTY_PAIR)
.collect(Collectors.toList());
Expand Down Expand Up @@ -163,9 +163,10 @@ List<PathPair> run(Field field, SizedBit sizedBit, BlockField blockField) throws
String fumen = fumenParser.parse(sampleOperations, field, maxClearLine);

HashSet<LongPieces> validPieces = piecesPool.getValidPieces();
long numOfValidSpecifiedPatterns = getNumOfValidSpecifiedPatterns(field, operations, maxClearLine);

return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(sampleOperations), validPieces, numOfValidSpecifiedPatterns);
HashSet<LongPieces> validSpecifiedPatterns = getValidSpecifiedPatterns(field, operations, maxClearLine);

return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(sampleOperations), validPieces, validSpecifiedPatterns);
})
.filter(pathPair -> pathPair != PathPair.EMPTY_PAIR)
.collect(Collectors.toList());
Expand Down Expand Up @@ -237,7 +238,7 @@ private HashSet<LongPieces> getPiecesPattern(HashSet<LongPieces> piecesSolution)
}
}

private long getNumOfValidSpecifiedPatterns(Field field, LinkedList<MinoOperationWithKey> operations, int maxClearLine) {
private HashSet<LongPieces> getValidSpecifiedPatterns(Field field, LinkedList<MinoOperationWithKey> operations, int maxClearLine) {
HashSet<LongPieces> allSpecifiedPieces = piecesPool.getAllSpecifiedPieces();

Reachable reachable = reachableThreadLocal.get();
Expand All @@ -248,14 +249,14 @@ private long getNumOfValidSpecifiedPatterns(Field field, LinkedList<MinoOperatio
.filter(pieces -> {
return BuildUp.existsValidByOrderWithHold(field, operations.stream(), pieces.getPieces(), maxClearLine, reachable, maxDepth);
})
.count();
.collect(Collectors.toCollection(HashSet::new));
} else {
// そのまま絞り込む
return allSpecifiedPieces.stream()
.filter(pieces -> {
return BuildUp.existsValidByOrder(field, operations.stream(), pieces.getPieces(), maxClearLine, reachable, maxDepth);
})
.count();
.collect(Collectors.toCollection(HashSet::new));
}
}
}
1 change: 1 addition & 0 deletions src/main/java/entry/path/PathOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum PathOptions {
PatternsPath(SingleArgOption.full("pp", "patterns-path", "path", "File path of pattern definition")),
Drop(SingleArgOption.full("d", "drop", "hard or soft", "Specify drop")),
Hold(SingleArgOption.full("H", "hold", "use or avoid", "If use hold, set 'use'. If not use hold, set 'avoid'")),
MinimalSpecifiedOnly(SingleArgOption.full("so", "specified-only", "yes or no", "Set 'yes' if refine the minimal solutions from the specified patterns, or 'no' from the patterns extended with hold")),
ClearLine(SingleArgOption.full("c", "clear-line", "number", "'Specify max clear line")),
MaxLayer(SingleArgOption.full("L", "max-layer", "int", "Specify max layer")),
Format(SingleArgOption.full("f", "format", "string", "Format type for output")),
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/entry/path/PathPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.stream.Stream;

public class PathPair implements HaveSet<LongPieces> {
static final PathPair EMPTY_PAIR = new PathPair(null, new HashSet<>(), null, "", Collections.emptyList(), new HashSet<>(), 0L);
static final PathPair EMPTY_PAIR = new PathPair(null, new HashSet<>(), null, "", Collections.emptyList(), new HashSet<>(), new HashSet<>());

private final Result result;
private final HashSet<LongPieces> piecesSolution;
Expand All @@ -25,17 +25,17 @@ public class PathPair implements HaveSet<LongPieces> {
private final boolean deletedLine;
private final HashSet<LongPieces> validPieces;

private final long numOfValidSpecifiedPatterns;
private final HashSet<LongPieces> validSpecifiedPatterns;

public PathPair(Result result, HashSet<LongPieces> piecesSolution, HashSet<LongPieces> piecesPattern, String fumen, List<MinoOperationWithKey> sampleOperations, HashSet<LongPieces> validPieces, long numOfValidSpecifiedPatterns) {
public PathPair(Result result, HashSet<LongPieces> piecesSolution, HashSet<LongPieces> piecesPattern, String fumen, List<MinoOperationWithKey> sampleOperations, HashSet<LongPieces> validPieces, HashSet<LongPieces> validSpecifiedPatterns) {
this.result = result;
this.piecesSolution = piecesSolution;
this.piecesPattern = piecesPattern;
this.fumen = fumen;
this.sampleOperations = sampleOperations;
this.deletedLine = result != null && containsDeletedLine();
this.validPieces = validPieces;
this.numOfValidSpecifiedPatterns = numOfValidSpecifiedPatterns;
this.validSpecifiedPatterns = validSpecifiedPatterns;
}

private boolean containsDeletedLine() {
Expand All @@ -44,8 +44,8 @@ private boolean containsDeletedLine() {
}

@Override
public Set<LongPieces> getSet() {
return blocksHashSetForPattern();
public Set<LongPieces> getSet(boolean specified_only) {
return specified_only ? blocksHashSetForSpecified() : blocksHashSetForPattern();
}

public Result getResult() {
Expand All @@ -56,7 +56,7 @@ public String getFumen() {
return fumen;
}

// すべての入力パターンの中で、その手順で対応できるツモ
// (未知のホールドも考慮した上で)入力される可能性のあるすべてのパターンの中で、その手順で対応できるツモ
// パターンで6ミノを設定したとき、このツモは6ミノになる
public HashSet<LongPieces> blocksHashSetForPattern() {
return piecesPattern;
Expand All @@ -82,6 +82,12 @@ public Stream<LongPieces> blocksStreamForValidSolution() {
return piecesSolution.stream().filter(validPieces::contains);
}

// 厳密に指定されたパターンの中で、その手順で対応できるツモ
// パターンで6ミノを設定したとき、このツモは6ミノになる
public HashSet<LongPieces> blocksHashSetForSpecified() {
return validSpecifiedPatterns;
}

public List<MinoOperationWithKey> getSampleOperations() {
return sampleOperations;
}
Expand All @@ -107,6 +113,6 @@ public boolean isDeletedLine() {
}

public long getNumOfValidSpecifiedPatterns() {
return numOfValidSpecifiedPatterns;
return validSpecifiedPatterns.size();
}
}
4 changes: 2 additions & 2 deletions src/main/java/entry/path/PathPairs.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public List<PathPair> getUniquePathPairList() {
return pathPairList;
}

public List<PathPair> getMinimalPathPairList() {
public List<PathPair> getMinimalPathPairList(boolean specified_only) {
Selector<PathPair, LongPieces> selector = new Selector<>(pathPairList);
return selector.select();
return selector.select(specified_only);
}
}
6 changes: 6 additions & 0 deletions src/main/java/entry/path/PathSettingParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ protected Optional<PathSettings> parse(CommandLineWrapper wrapper) throws Finder
Optional<Boolean> isUsingHold = wrapper.getBoolOption(PathOptions.Hold.optName());
isUsingHold.ifPresent(settings::setUsingHold);

// Minimalの厳密化
Optional<Boolean> isMinimalSpecifiedOnly = wrapper.getBoolOption(
PathOptions.MinimalSpecifiedOnly.optName()
);
isMinimalSpecifiedOnly.ifPresent(settings::setMinimalSpecifiedOnly);

// キャッシュ
Optional<Integer> cachedMinBit = wrapper.getIntegerOption(PathOptions.CachedBit.optName());
cachedMinBit.ifPresent(settings::setCachedMinBit);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/entry/path/PathSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PathSettings {
private boolean isReserved = false;
private DropType dropType = DropType.Softdrop;
private int threadCount = -1;
private boolean isMinimalSpecifiedOnly = true;

// ********* Getter ************
public boolean isUsingHold() {
Expand Down Expand Up @@ -93,6 +94,10 @@ DropType getDropType() {
return dropType;
}

public boolean getMinimalSpecifiedOnly() {
return isMinimalSpecifiedOnly;
}

// ********* Setter ************
void setMaxClearLine(int maxClearLine) {
this.maxClearLine = maxClearLine;
Expand Down Expand Up @@ -231,4 +236,8 @@ void setDropType(String type) throws FinderParseException {
throw new FinderParseException("Unsupported droptype: type=" + type);
}
}

public void setMinimalSpecifiedOnly(boolean isMinimalSpecifiedOnly) {
this.isMinimalSpecifiedOnly = isMinimalSpecifiedOnly;
}
}
11 changes: 7 additions & 4 deletions src/main/java/entry/path/Selector.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package entry.path;

import java.util.*;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class Selector<K extends HaveSet<V>, V> {
private final List<K> candidates;
Expand All @@ -9,19 +12,19 @@ public Selector(List<K> candidates) {
this.candidates = candidates;
}

public List<K> select() {
public List<K> select(boolean specified_only) {
// 他のパターンではカバーできないものだけを列挙する
LinkedList<K> selected = new LinkedList<>();

for (K pair : candidates) {
Set<V> canBuildBlocks = pair.getSet();
Set<V> canBuildBlocks = pair.getSet(specified_only);
boolean isSetNeed = true;
LinkedList<K> nextMasters = new LinkedList<>();

// すでに登録済みのパターンでカバーできるか確認
while (!selected.isEmpty()) {
K targetPair = selected.pollFirst();
Set<V> registeredBlocks = targetPair.getSet();
Set<V> registeredBlocks = targetPair.getSet(specified_only);

if (registeredBlocks.size() < canBuildBlocks.size()) {
// 新しいパターンの方が多く対応できる // 新パターンが残る
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/entry/path/output/CSVPathOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public void output(PathPairs pathPairs, Field field, SizedBit sizedBit) throws F

// 少ないパターンでカバーできるパスを出力
if (pathLayer.contains(PathLayer.Minimal)) {
Selector<PathPair, LongPieces> selector = new Selector<>(pathPairList);
List<PathPair> minimal = selector.select();
List<PathPair> minimal = pathPairs.getMinimalPathPairList(settings.getMinimalSpecifiedOnly());
outputLog("Found path [minimal] = " + minimal.size());
outputOperationsToCSV(field, outputMinimalFile, minimal, sizedBit);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/entry/path/output/LinkPathOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void output(PathPairs pathPairs, Field field, SizedBit sizedBit) throws F

// 少ないパターンでカバーできるパスを出力
if (pathLayer.contains(PathLayer.Minimal)) {
List<PathPair> pathPairList = pathPairs.getMinimalPathPairList();
List<PathPair> pathPairList = pathPairs.getMinimalPathPairList(settings.getMinimalSpecifiedOnly());

outputLog("Found path [minimal] = " + pathPairList.size());
outputOperationsToSimpleHTML(field, outputMinimalFile, pathPairList, sizedBit, numOfAllPatternSequences);
Expand Down Expand Up @@ -155,7 +155,7 @@ private void outputOperationsToSimpleHTML(Field field, MyFile file, List<PathPai

if (!pathPairs.isEmpty()) {
String mergedFumen = bufferedFumenParser.parse();
htmlBuilder.addHeader(String.format("<div><a href='http://fumen.zui.jp/?v115@%s'>All solutions<a></div>", mergedFumen));
htmlBuilder.addHeader(String.format("<div><a href='http://fumen.zui.jp/?v115@%s'>All solutions</a></div>", mergedFumen));
}

// 出力
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/entry/setup/output/LinkSetupOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void output(SetupResults setupResults, Field initField, SizedBit sizedBit
}

String mergedFumen = bufferedFumenParser.parse();
htmlBuilder.addHeader(String.format("<div><a href='http://fumen.zui.jp/?v115@%s'>All solutions<a></div>", mergedFumen));
htmlBuilder.addHeader(String.format("<div><a href='http://fumen.zui.jp/?v115@%s'>All solutions</a></div>", mergedFumen));

ArrayList<HTMLColumn> columns = new ArrayList<>(htmlBuilder.getRegisteredColumns());
columns.sort(Comparator.comparing(HTMLColumn::getTitle).reversed());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/_usecase/path/PathCSVCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void none1() throws Exception {
.contains("I,*p6")
.contains(Messages.clearLine(4))
.contains(Messages.uniqueCount(186))
.contains(Messages.minimalCount(142))
.contains(Messages.minimalCount(127))
.contains(Messages.useHold());

assertThat(log.getReturnCode()).isEqualTo(0);
Expand Down Expand Up @@ -91,7 +91,7 @@ void none1() throws Exception {
}
return freeze;
}))
.hasSize(142)
.hasSize(127)
.allMatch(Field::isPerfect);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/_usecase/path/PathCountCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void pattern7() throws Exception {
assertThat(log.getOutput())
.contains("*,*p4")
.contains(Messages.uniqueCount(298))
.contains(Messages.minimalCount(239))
.contains(Messages.minimalCount(172))
.contains(Messages.useHold());
}

Expand All @@ -200,7 +200,7 @@ void pattern8() throws Exception {
assertThat(log.getOutput())
.contains("S,L,O,I,T")
.contains(Messages.uniqueCount(3))
.contains(Messages.minimalCount(3))
.contains(Messages.minimalCount(1))
.contains(Messages.useHold());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/_usecase/path/PathOptionCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void page() throws Exception {
.contains("S,[TIOJLZ]p6")
.contains(Messages.clearLine(4))
.contains(Messages.uniqueCount(95))
.contains(Messages.minimalCount(47))
.contains(Messages.minimalCount(42))
.contains(Messages.useHold());
}

Expand Down Expand Up @@ -149,7 +149,7 @@ void singleThread() throws Exception {
.contains(Messages.singleThread())
.contains(Messages.clearLine(4))
.contains(Messages.uniqueCount(186))
.contains(Messages.minimalCount(144))
.contains(Messages.minimalCount(138))
.contains(Messages.useHold());
}
}
Loading

0 comments on commit 85b4766

Please sign in to comment.