-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from LyashenkoGS/DFSmethods
Simplest working algorithms
- Loading branch information
Showing
18 changed files
with
866 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
#Java and Intellij specific | ||
#Java and Intellij & Eclipse specific | ||
.idea | ||
*.iml | ||
.project | ||
.classpath | ||
.project | ||
target | ||
#ignore the archived source code | ||
*.zip | ||
#ignore the archived source code and output files | ||
/outputDataSet/* | ||
*.zip | ||
/.classpath | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
3 | ||
0 0 2 1 | ||
0 2 2 2 | ||
0 3 2 4 | ||
0 3 2 4 | ||
0 0 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
package com.google.hashcode; | ||
|
||
import com.google.hashcode.entity.Cell; | ||
import com.google.hashcode.entity.Pizza; | ||
import com.google.hashcode.entity.Slice; | ||
import com.google.hashcode.entity.Step; | ||
import com.google.hashcode.utils.DFSMethods; | ||
import com.google.hashcode.utils.IoUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static com.google.hashcode.utils.FilesPaths.*; | ||
|
||
|
||
public class App { | ||
public static void main(String[] args) throws IOException { | ||
String exampleInputFile = "inputDataSets/example.in"; | ||
Cell[][] ingredients = IoUtils.parsePizza(exampleInputFile); | ||
Pizza pizza = new Pizza(new File(exampleInputFile), ingredients, IoUtils.parseSliceInstructions(exampleInputFile)); | ||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | ||
|
||
System.out.println("GoogleHashCode2017! Pizza task"); | ||
System.out.print(pizza); | ||
public static void main(String[] args) throws IOException { | ||
slicePizza(EXAMPLE_INPUT_FILE_PATH, OUTPUT_DATA_SET_EXAMPLE_TXT); | ||
slicePizza(SMALL_INPUT_FILE_PATH, OUTPUT_DATA_SET_SMALL_TXT); | ||
//TODO troubles to input big files, possible exciting String max size | ||
//slicePizza(BIG_INPUT_FILE_PATH, OUTPUT_DATA_SET_BIG_TXT); | ||
//slicePizza(MEDIUM_INPUT_FILE_PATH, OUTPUT_DATA_SET_MEDIUM_TXT); | ||
} | ||
|
||
public static void slicePizza(String inputFile, String outputFile) throws IOException { | ||
List<Slice> output; | ||
Pizza pizza = new Pizza(new File(inputFile), IoUtils.parsePizza(inputFile), IoUtils.parseSliceInstructions(inputFile)); | ||
//get start positions | ||
output = DFSMethods.cutAllStartPositions(pizza); | ||
//get All steps | ||
Map<Slice, List<Step>> availableSteps = DFSMethods.getAvailableSteps(pizza, output); | ||
while (!availableSteps.values().stream().allMatch(List::isEmpty)) { | ||
Step step = DFSMethods.selectStep(availableSteps); | ||
output.remove(step.startPosition); | ||
output.add(DFSMethods.performStep(pizza, step)); | ||
//TODO available steps should include merging slices to each other | ||
availableSteps = DFSMethods.getAvailableSteps(pizza, output); | ||
LOGGER.info("OUTPUT AFTER A STEP: " | ||
+ "\n " + output); | ||
} | ||
IoUtils.writeToFile(outputFile, IoUtils.parseSlices(output)); | ||
LOGGER.info("FINISHED for " + inputFile + "!!!!!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
package com.google.hashcode.entity; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a pizza cell with it coordinates. There is no getters/setters for simplicity | ||
* | ||
* @author Grigoriy Lyashenko (Grog). | ||
*/ | ||
public class Cell { | ||
public final int x; | ||
public final int y; | ||
public final Ingredient ingredient; | ||
public int y; | ||
public int x; | ||
public Ingredient ingredient; | ||
|
||
public Cell(int x, int y, Ingredient ingredient) { | ||
this.x = x; | ||
public Cell(int y, int x, Ingredient ingredient) { | ||
this.y = y; | ||
this.x = x; | ||
this.ingredient = ingredient; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ingredient.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof Cell)) return false; | ||
Cell cell = (Cell) o; | ||
return x == cell.x && | ||
y == cell.y && | ||
ingredient == cell.ingredient; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, y, ingredient); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.