Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ yield buildSingleDirectionalParentGraph(solutionDescriptor,
graphStructureAndDirection,
entities);
}
case ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE ->
case ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE ->
buildArbitrarySingleEntityGraph(solutionDescriptor, variableReferenceGraphBuilder, entities, graphCreator);
case NO_DYNAMIC_EDGES, ARBITRARY ->
buildArbitraryGraph(solutionDescriptor, variableReferenceGraphBuilder, entities, graphCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum GraphStructure {
* entity that uses declarative shadow variables with all directional
* parents being the same type.
*/
ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE,
ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE,

/**
* A graph structure that accepts all graphs.
Expand Down Expand Up @@ -73,7 +73,7 @@ public static <Solution_> GraphStructureAndDirection determineGraphStructure(
.distinct().count() > 1;

final var arbitraryGraphStructure = new GraphStructureAndDirection(
multipleDeclarativeEntityClasses ? ARBITRARY : ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE,
multipleDeclarativeEntityClasses ? ARBITRARY : ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE,
null, null);

var rootVariableSources = declarativeShadowVariableDescriptors.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static <Entity_, Value_> RootVariableSource<Entity_, Value_> from(
assertIsValidVariableReference(rootEntityClass, variablePath, variableSourceReference);
}

if (parentVariableType != ParentVariableType.GROUP && variableSourceReferences.size() == 1) {
if (!parentVariableType.isIndirect() && variableSourceReferences.size() == 1) {
// No variables are accessed from the parent, so there no
// parent variable.
parentVariableType = ParentVariableType.NO_PARENT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ai.timefold.solver.core.impl.domain.variable.declarative;

import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.ARBITRARY;
import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE;
import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE;
import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.EMPTY;
import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.NO_DYNAMIC_EDGES;
import static ai.timefold.solver.core.impl.domain.variable.declarative.GraphStructure.SINGLE_DIRECTIONAL_PARENT;
import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -53,7 +52,7 @@ void simpleChainedStructure() {
var entity = new TestdataChainedSimpleVarValue();
assertThat(GraphStructure.determineGraphStructure(
TestdataChainedSimpleVarSolution.buildSolutionDescriptor(), entity))
.hasFieldOrPropertyWithValue("structure", ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE);
.hasFieldOrPropertyWithValue("structure", ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE);
}

@Test
Expand Down Expand Up @@ -94,15 +93,15 @@ void concurrentValuesStructureWithGroups() {
assertThat(GraphStructure.determineGraphStructure(
TestdataConcurrentSolution.buildSolutionDescriptor(),
value1, value2))
.hasFieldOrPropertyWithValue("structure", ARBITRARY_SINGLE_ENTITY_SINGLE_DIRECTIONAL_PARENT_TYPE);
.hasFieldOrPropertyWithValue("structure", ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE);
}

@Test
void followerStructure() {
var entity = new TestdataFollowerEntity();
assertThat(GraphStructure.determineGraphStructure(
TestdataFollowerSolution.buildSolutionDescriptor(), entity))
.hasFieldOrPropertyWithValue("structure", NO_DYNAMIC_EDGES);
.hasFieldOrPropertyWithValue("structure", ARBITRARY_SINGLE_ENTITY_AT_MOST_ONE_DIRECTIONAL_PARENT_TYPE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void pathUsingBuiltinShadow() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.NO_PARENT);
var source = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(source);
Expand Down Expand Up @@ -112,6 +113,7 @@ void pathUsingDeclarativeShadow() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.NO_PARENT);
var source = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(source);
Expand Down Expand Up @@ -145,6 +147,7 @@ void pathUsingDeclarativeShadowAfterGroup() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.GROUP);
var source = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(source);
Expand Down Expand Up @@ -183,6 +186,7 @@ void pathUsingBuiltinShadowAfterGroup() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.GROUP);
var source = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(source);
Expand Down Expand Up @@ -221,6 +225,7 @@ void pathUsingDeclarativeShadowAfterGroupAfterFact() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.GROUP);
var source = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(source);
Expand Down Expand Up @@ -261,6 +266,7 @@ void pathUsingDeclarativeShadowAfterBuiltinShadow() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(2);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.PREVIOUS);
var previousSource = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(previousSource);
Expand Down Expand Up @@ -305,6 +311,7 @@ void pathUsingBuiltinShadowAfterFact() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(1);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.INDIRECT);
var previousSource = rootVariableSource.variableSourceReferences().get(0);

assertChainToVariableEntity(previousSource, "fact");
Expand Down Expand Up @@ -344,6 +351,7 @@ void pathUsingDeclarativeShadowAfterBuiltinShadowAfterGroup() {

assertThat(rootVariableSource.rootEntity()).isEqualTo(TestdataInvalidDeclarativeValue.class);
assertThat(rootVariableSource.variableSourceReferences()).hasSize(2);
assertThat(rootVariableSource.parentVariableType()).isEqualTo(ParentVariableType.GROUP);
var previousSource = rootVariableSource.variableSourceReferences().get(0);

assertEmptyChainToVariableEntity(previousSource);
Expand Down
Loading