dghf
dghf
JCHJava Community | Help. Code. Learn.
Created by dghf on 4/5/2025 in #java-help
`java.lang.NumberFormatException` in StreamCipher - Key Parsing Issue
Oh sorry, I forgot to compile!
java StreamCipher --key $(<key.txt) --in plain.txt --out cipher-test.data
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing) with quotes: "4294966017"
Seed value after parsing: 4294966017
java StreamCipher --key $(<key.txt) --in plain.txt --out cipher-test.data
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing) with quotes: "4294966017"
Seed value after parsing: 4294966017
Is this good?
12 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 4/5/2025 in #java-help
`java.lang.NumberFormatException` in StreamCipher - Key Parsing Issue
I got
java StreamCipher --key $(<key.txt) --in plain.txt --out cipher-test.data
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing) with quotes: "4294966017"
Exception in thread "main" java.lang.NumberFormatException: For input string: "4294966017"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:778)
at StreamCipher.main(StreamCipher.java:21)
java StreamCipher --key $(<key.txt) --in plain.txt --out cipher-test.data
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing) with quotes: "4294966017"
Exception in thread "main" java.lang.NumberFormatException: For input string: "4294966017"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:778)
at StreamCipher.main(StreamCipher.java:21)
after switching to Long.parseLong(key);
12 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 4/5/2025 in #java-help
`java.lang.NumberFormatException` in StreamCipher - Key Parsing Issue
So I should change it from seed = Integer.parseInt(key); to seed = Long.parseLong(key);?
12 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 4/5/2025 in #java-help
`java.lang.NumberFormatException` in StreamCipher - Key Parsing Issue
However, when I run this, I get the following error:
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing): '4294966017'
Exception in thread "main" java.lang.NumberFormatException: For input string: "4294966017"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:778)
at StreamCipher.main(StreamCipher.java:20)
Command line arguments received: [--key, 4294966017, --in, plain.txt, --out, cipher-test.data]
Key argument (before parsing): '4294966017'
Exception in thread "main" java.lang.NumberFormatException: For input string: "4294966017"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:778)
at StreamCipher.main(StreamCipher.java:20)
12 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
We'll verify that employees do not exceed their assigned work percentage. For example, if an employee has a 1% work percentage, they should only be assigned shifts that fit within that limit.
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@dan1st | Daniel
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Hmm I am not sure how that'd be done. Any suggestions?
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@dan1st | Daniel
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Like why do we subtract 0.0001 from desiredHours?
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Yeah
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
But why
return totalWorkedHours.toHours() < desiredHours - 0.0001
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
I think return totalWorkedHours.toHours() < desiredHours should be ok
we've tried this but it didn't work
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Yeah, but do you know what could be the issue instead? Should we do more logging somewhere to see what could be causing the issue along the way?
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
The problem could lie somewhere in the logic here
public Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Employee.class)
.join(Shift.class, equal(Employee::getName, Shift::getEmployee))
.groupBy(
(employee, shift) -> employee,
ConstraintCollectors.sumDuration((employee, shift) ->
Duration.between(shift.getStart(), shift.getEnd()))
)
.filter((employee, totalWorkedHours) -> {
double fullTimeHours = 40.0;
double desiredHours = employee.getWorkPercentage() * fullTimeHours;
return totalWorkedHours.toHours() != desiredHours;
})
.penalize(HardSoftBigDecimalScore.ONE_HARD, (employee, totalWorkedHours) -> {
return (int) totalWorkedHours.toHours() - employee.getWorkPercentage() * 40;
})
.asConstraint("Employee work percentage not matched");
}
public Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Employee.class)
.join(Shift.class, equal(Employee::getName, Shift::getEmployee))
.groupBy(
(employee, shift) -> employee,
ConstraintCollectors.sumDuration((employee, shift) ->
Duration.between(shift.getStart(), shift.getEnd()))
)
.filter((employee, totalWorkedHours) -> {
double fullTimeHours = 40.0;
double desiredHours = employee.getWorkPercentage() * fullTimeHours;
return totalWorkedHours.toHours() != desiredHours;
})
.penalize(HardSoftBigDecimalScore.ONE_HARD, (employee, totalWorkedHours) -> {
return (int) totalWorkedHours.toHours() - employee.getWorkPercentage() * 40;
})
.asConstraint("Employee work percentage not matched");
}
(from the OP)
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@dan1st | Daniel But even if we count in minutes instead of hours, shouldn't workpercentage being 0 mean that no shifts are assigned to that particular employee?
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@ayylmao123xdd so doing this?
.filter((employee, totalWorkedHours) -> {
double fullTimeHours = 160; // Assume 40 hours as full-time
double maxAllowedHours = (employee.getWorkPercentage() * fullTimeHours) / 100;
double currentShiftHours = Duration.between(shift.getStart(), shift.getEnd()).toHours();
return (totalWorkedHours + currentShiftHours) <= maxAllowedHours && employee.getWorkPercentage() > 0;
})
.filter((employee, totalWorkedHours) -> {
double fullTimeHours = 160; // Assume 40 hours as full-time
double maxAllowedHours = (employee.getWorkPercentage() * fullTimeHours) / 100;
double currentShiftHours = Duration.between(shift.getStart(), shift.getEnd()).toHours();
return (totalWorkedHours + currentShiftHours) <= maxAllowedHours && employee.getWorkPercentage() > 0;
})
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@dan1st | Daniel
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
@dan1st | Daniel
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
The code is using a library called Timefold Solver, which is a constraint solver. It is used for solving planning and scheduling problems by defining constraints and optimizing solutions based on those constraints. The constraints are defined in our EmployeeSchedulingConstraintProvider class, using the Timefold Solver's API, which includes classes like ConstraintFactory, ConstraintCollectors, and HardSoftBigDecimalScore. These are used to define and manage constraints for employee scheduling, such as ensuring no overlapping shifts, respecting employee preferences, and balancing shift assignments.
154 replies