Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import data from json file #20

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d263918
Add import and export data
NogameNo-life Nov 18, 2024
746a83b
replace xml reading by json
NogameNo-life Nov 18, 2024
38414a6
add @type in json
NogameNo-life Nov 20, 2024
3230fb7
Add class JsonImporter, change data.json
NogameNo-life Nov 28, 2024
e17a2cc
Change json data
NogameNo-life Dec 4, 2024
d76814e
Add jsonImporeter object
Dec 4, 2024
a96d584
Add variables from json
NogameNo-life Dec 5, 2024
0fe8a47
add class DataModel
NogameNo-life Dec 6, 2024
1a4f4f1
Implementation DataModel
NogameNo-life Dec 6, 2024
e87a6e3
Add javax for json reading
NogameNo-life Dec 9, 2024
bc96d78
fix compile
NogameNo-life Dec 9, 2024
0b67309
add printdata method
NogameNo-life Dec 10, 2024
1788563
remove costructor DataModel
NogameNo-life Dec 10, 2024
48caaeb
return succcessorjoblist
NogameNo-life Dec 11, 2024
6e38143
Remake settters
NogameNo-life Dec 11, 2024
d0f6418
Add rootNode
NogameNo-life Dec 11, 2024
f2b939d
Read successsors and restriction lists
NogameNo-life Dec 12, 2024
bdc8cba
add initialisation for lists DataModel
NogameNo-life Dec 13, 2024
49786c4
add reading in HashMap
NogameNo-life Dec 13, 2024
a515998
remove javax dependency
NogameNo-life Dec 13, 2024
1c2588d
init projectslist
NogameNo-life Dec 13, 2024
2759edf
init lists in DataModel from HashMap
NogameNo-life Dec 16, 2024
1264f9c
remove initexecutionModeList method
NogameNo-life Dec 16, 2024
86ad57c
delete comment code
NogameNo-life Dec 17, 2024
ae512fb
Add projects and resources lists in projobschedule
NogameNo-life Dec 18, 2024
fe52b8a
Add data output
NogameNo-life Dec 18, 2024
3ed2589
read successorLisrt
NogameNo-life Dec 23, 2024
53f0e31
read excutionMode
NogameNo-life Dec 23, 2024
d95615d
read resourceRequirement
NogameNo-life Dec 23, 2024
7c2ca5a
что-то сделано, я не помню что
NogameNo-life Dec 24, 2024
59da5a7
inti Job & executionMode
NogameNo-life Dec 26, 2024
63653f8
сделано все кроме allocation
NogameNo-life Dec 27, 2024
bfd5910
add pair
NogameNo-life Dec 30, 2024
39b24ef
init allocations
NogameNo-life Dec 30, 2024
aaf0f2f
Remove output data
NogameNo-life Dec 31, 2024
4cc26dc
remove spaces
NogameNo-life Dec 31, 2024
4e35d7d
remove jsonproperty
NogameNo-life Dec 31, 2024
cf15677
remove space
NogameNo-life Dec 31, 2024
af7aab9
delete comments
NogameNo-life Dec 31, 2024
c53e01c
remove space
NogameNo-life Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/org/acme/projectjobschedule/app/JsonImporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.acme.projectjobschedule.app;

import org.acme.projectjobschedule.domain.ProjectJobSchedule;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.File;

public class JsonImporter {
public ProjectJobSchedule importFromJson(String filePath) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
File jsonFile = new File(filePath);

// Десериализация JSON-файла в объект ProjectJobSchedule
ProjectJobSchedule projectJobSchedule = objectMapper.readValue(jsonFile, ProjectJobSchedule.class);

return projectJobSchedule;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ai.timefold.solver.core.api.solver.Solver;
import ai.timefold.solver.core.api.solver.SolverFactory;
import ai.timefold.solver.core.config.solver.SolverConfig;;
import ai.timefold.solver.core.config.solver.SolverConfig;
import org.acme.projectjobschedule.domain.Allocation;
import org.acme.projectjobschedule.domain.Job;
import org.acme.projectjobschedule.domain.Project;
Expand All @@ -19,6 +19,13 @@
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import org.acme.projectjobschedule.app.JsonImporter;
import java.nio.file.Path;
import java.nio.file.Paths;


public class ProjectJobScheduleApp {

private static final Logger LOGGER = LoggerFactory.getLogger(ProjectJobScheduleApp.class);
Expand All @@ -28,7 +35,9 @@ public enum DemoData {
LARGE
}


public static void main(String[] args) {

SolverFactory<ProjectJobSchedule> solverFactory = SolverFactory.create(new SolverConfig()
.withSolutionClass(ProjectJobSchedule.class)
.withEntityClasses(Allocation.class)
Expand All @@ -38,16 +47,31 @@ public static void main(String[] args) {
.withTerminationSpentLimit(Duration.ofSeconds(5)));

// Load the problem
DemoDataGenerator demo_data = new DemoDataGenerator();
ProjectJobSchedule problem = demo_data.generateDemoData();

// Solve the problem
Solver<ProjectJobSchedule> solver = solverFactory.buildSolver();
ProjectJobSchedule solution = solver.solve(problem);
// DemoDataGenerator demo_data = new DemoDataGenerator();
// ProjectJobSchedule problem = demo_data.generateDemoData();

// Load the problem from JSON
JsonImporter importer = new JsonImporter();
try {
ProjectJobSchedule problem = importer.importFromJson("src/main/resources/data.json");
// Теперь у вас есть объект ProjectJobSchedule, заполненный данными из JSON-файла
System.out.println(problem);

// Solve the problem
Solver<ProjectJobSchedule> solver = solverFactory.buildSolver();
ProjectJobSchedule solution = solver.solve(problem);

// Visualize the solution
printProjectJobSchedule(solution);

// Visualize the solution
printProjectJobSchedule(solution);
} catch (IOException e) {
e.printStackTrace();
}

// Visualize the solution
printProjectJobSchedule(solution);
}

public static void printProjectJobSchedule(ProjectJobSchedule schedule){
LOGGER.info("");
List<Project> projects = schedule.getProjects();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@JsonIdentityInfo(scope = Project.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
Expand Down
61 changes: 61 additions & 0 deletions src/main/resources/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"projects": [
{
"id": "P1",
"releaseDate": 10,
"criticalPathDuration": 50
},
{
"id": "P2",
"releaseDate": 15,
"criticalPathDuration": 60
}
],
"resources": [
{
"id": "R1",
"capacity": 100,
"@type": "global"
},
{
"id": "R2",
"capacity": 200,
"@type": "local"
}
],
"jobs": [
{
"id": "J1",
"project": "P1",
"jobType": "SOURCE"
},
{
"id": "J2",
"project": "P1",
"jobType": "STANDARD"
},
{
"id": "J3",
"project": "P2",
"jobType": "SINK"
}
],
"allocations": [
{
"id": "A1",
"job": "J1",
"sourceAllocation": "A1",
"sinkAllocation": "A2",
"predecessorAllocations": ["A1"],
"successorAllocations": ["A2"]
},
{
"id": "A2",
"job": "J2",
"sourceAllocation": "A1",
"sinkAllocation": "A2",
"predecessorAllocations": ["A1"],
"successorAllocations": ["A2"]
}
]
}