-
Notifications
You must be signed in to change notification settings - Fork 1
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
Shortest path constraint #9
Open
waneck
wants to merge
19
commits into
main
Choose a base branch
from
shortest-path-constraint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9a72fb5
creating the base class
prolecengelhard 6e73ba3
redid it with virtual functions
prolecengelhard 537e7ac
removed redundant function
prolecengelhard 5f34fe1
implemented isValidDistance
prolecengelhard cb43719
added db to callback
prolecengelhard 077bd4b
adding db to addSource
prolecengelhard 460175f
moved the explainers down to the ReachabilityConstraint
prolecengelhard b96a1de
about to attempt to restructure the maze
prolecengelhard 84c01a8
working on greater than and less than
prolecengelhard 0364754
Merge branch 'main' into shortest-path-constraint
prolecengelhard 61add3f
still trying to figure out the constraints
prolecengelhard 1073622
made a simpler test and renamed a function
prolecengelhard 388e7c6
Fixes so that the ReachabilityConstraint works again
waneck 4145f24
Merge branch 'main' into shortest-path-constraint-v2
waneck 07f0414
Introduce the split between Valid vs Reachable
waneck 4944159
Working shortest path constraint
waneck 092f5c0
Initial explainInvalid implementation
waneck fdc4d2a
Working greater than explainer
waneck 80ae90e
PR feedback, part one
waneck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,037 changes: 18 additions & 1,019 deletions
1,037
vertexy/src/private/constraints/ReachabilityConstraint.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
596 changes: 596 additions & 0 deletions
596
vertexy/src/private/constraints/ShortestPathConstraint.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
1,143 changes: 1,143 additions & 0 deletions
1,143
vertexy/src/private/constraints/TopologySearchConstraint.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
101 changes: 101 additions & 0 deletions
101
vertexy/src/public/constraints/ShortestPathConstraint.h
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright Proletariat, Inc. All Rights Reserved. | ||
#pragma once | ||
#include "ConstraintTypes.h" | ||
#include "TopologySearchConstraint.h" | ||
#include "IConstraint.h" | ||
#include "SignedClause.h" | ||
#include "ds/ESTree.h" | ||
#include "ds/RamalReps.h" | ||
#include "topology/BacktrackingDigraphTopology.h" | ||
#include "topology/DigraphEdgeTopology.h" | ||
#include "topology/TopologyVertexData.h" | ||
#include "topology/algo/MaxFlowMinCut.h" | ||
#include "topology/algo/ShortestPath.h" | ||
#include "variable/IVariableDatabase.h" | ||
#include "constraints/ConstraintOperator.h" | ||
#include "ds/BacktrackableValue.h" | ||
|
||
#define REACHABILITY_USE_RAMAL_REPS 1 | ||
|
||
namespace Vertexy | ||
{ | ||
|
||
/** Constraint to ensure the shortest paths between source and destination nodes | ||
* All destination nodes must have at least 1 shortest path to at least 1 source node | ||
* this shortest path must have a relation with 'distance' | ||
*/ | ||
class ShortestPathConstraint : public ITopologySearchConstraint | ||
{ | ||
public: | ||
ShortestPathConstraint(const ConstraintFactoryParams& params, | ||
const shared_ptr<TTopologyVertexData<VarID>>& sourceGraphData, | ||
const ValueSet& sourceMask, | ||
const ValueSet& requireReachableMask, | ||
const shared_ptr<TTopologyVertexData<VarID>>& edgeGraphData, | ||
const ValueSet& edgeBlockedMask, | ||
EConstraintOperator op, | ||
VarID distance | ||
); | ||
|
||
struct ShortestPathFactory | ||
{ | ||
static ShortestPathConstraint* construct( | ||
const ConstraintFactoryParams& params, | ||
// Graph of vertices where reachability is calculated | ||
const shared_ptr<TTopologyVertexData<VarID>>& sourceGraphData, | ||
// Values of vertices in SourceGraph that establish it as a reachability source | ||
const vector<int>& sourceValues, | ||
// Values of vertices in SourceGraph that establish it as needing to be reachable from a source | ||
const vector<int>& needReachableValues, | ||
// The variables for each edge of source graph | ||
const shared_ptr<TTopologyVertexData<VarID>>& edgeGraphData, | ||
// Values of vertices in the edge graph establishing that edge as "off" | ||
const vector<int>& edgeBlockedValues, | ||
// How to compare distance | ||
EConstraintOperator op, | ||
// The variable that stores the distance | ||
VarID distance); | ||
}; | ||
|
||
using Factory = ShortestPathFactory; | ||
|
||
virtual EConstraintType getConstraintType() const override { return EConstraintType::ShortestPath; } | ||
virtual void onInitialArcConsistency(IVariableDatabase* db) override; | ||
|
||
protected: | ||
|
||
bool isValidDistance(const IVariableDatabase* db, int dist) const; | ||
|
||
virtual bool isPossiblyValid(const IVariableDatabase* db, const ReachabilitySourceData& src, int vertex) override; | ||
virtual EValidityDetermination determineValidityHelper(const IVariableDatabase* db, const ReachabilitySourceData& src, int vertex, VarID srcVertex) override; | ||
virtual shared_ptr<RamalRepsType> makeTopology(const shared_ptr<BacktrackingDigraphTopology>& graph) const override; | ||
virtual EventListenerHandle addMinCallback(RamalRepsType& minReachable, const IVariableDatabase* db, VarID source) override; | ||
virtual EventListenerHandle addMaxCallback(RamalRepsType& maxReachable, const IVariableDatabase* db, VarID source) override; | ||
virtual vector<Literal> explainInvalid(const NarrowingExplanationParams& params) override; | ||
virtual void createTempSourceData(ReachabilitySourceData& data, int vertexIndex) const override; | ||
void onVertexChanged(int vertexIndex, VarID sourceVar, bool inMinGraph); | ||
void backtrack(const IVariableDatabase* db, SolverDecisionLevel level) override; | ||
|
||
EConstraintOperator m_op; | ||
VarID m_distance; | ||
|
||
// used to determine the path that is either too long or too short when explaning | ||
ShortestPathAlgorithm m_shortestPathAlgo; | ||
|
||
// used when m_op is LessThan/LessThanEq and records the last timestamp in which a vertex was deemed valid | ||
hash_map<int, hash_map<int, TBacktrackableValue<SolverTimestamp>>> m_lastValidTimestamp; | ||
hash_map<int, hash_map<int, SolverTimestamp>> m_validTimestampsToCommit; | ||
hash_set<tuple<int, int>> m_alwaysForbiddenPaths; | ||
|
||
hash_set<int> m_queuedVertexChanges; | ||
bool m_processingVertices = false; | ||
|
||
void commitValidTimestamps(const IVariableDatabase* db); | ||
void onEdgeChangeFailure(const IVariableDatabase* db) override; | ||
void onEdgeChangeSuccess(const IVariableDatabase* db) override; | ||
void addTimestampToCommit(const IVariableDatabase* db, int sourceVertex, int destVertex); | ||
void removeTimestampToCommit(const IVariableDatabase* db, int sourceVertex, int destVertex); | ||
void processQueuedVertexChanges(IVariableDatabase* db) override; | ||
}; | ||
|
||
} // namespace Vertexy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it doesn't appear like we're handling a distance that isn't predefined. I.e. we're not listening for changes on this variable, updating vertices in response. Since that's basically a whole new feature, I suggest just changing this to an
int
for now.