-
-
Notifications
You must be signed in to change notification settings - Fork 0
[Fix] Making SubstituteAccordingTo relies on BOTH the variable ID AND the environment
#31
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ea5c57
Fixed tests to use the new Environment interface
ee1ffef
Adding test to verify that our change works as intended
4ff4db5
Reworked TrackVariable() signature to return true or not (whether or …
a96ee24
Update symbolic/variable.go
kwesiRutledge 3f77021
Update symbolic/variable.go
kwesiRutledge 0f2a040
updating tests and variable interfaces to use the proper reference to…
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
This file contains hidden or 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,26 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/MatProGo-dev/SymbolicMath.go/symbolic" | ||
|
|
||
| "gonum.org/v1/gonum/mat" | ||
| ) | ||
|
|
||
| func main() { | ||
| // Create the variables | ||
| N := 2 | ||
| x := symbolic.NewVariableVector(N) | ||
|
|
||
| // Create the constraints | ||
| // - x >= -1 | ||
| c1 := x.GreaterEq(mat.NewVecDense(N, []float64{-1, -1})) | ||
|
|
||
| // - x <= 1 | ||
| c2 := x.LessEq(symbolic.OnesVector(N)) | ||
|
|
||
| // Print the constraints | ||
| fmt.Println("Constraint 1:", c1) | ||
| fmt.Println("Constraint 2:", c2) | ||
| } |
This file contains hidden or 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,45 @@ | ||
| package symbolic | ||
|
|
||
| type BasicEnvironment struct { | ||
| name string | ||
| Variables []Variable | ||
| } | ||
|
|
||
| func (be *BasicEnvironment) GetName() string { | ||
| return be.name | ||
| } | ||
|
|
||
| func (be *BasicEnvironment) TrackVariable(v Variable) bool { | ||
| // Check if the variable is already in the environment | ||
| for _, existingVar := range be.Variables { | ||
| if existingVar.ID == v.ID { | ||
| // Variable already exists, do not add it again | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // Add the variable to the environment | ||
| be.Variables = append(be.Variables, v) | ||
| return true // Variable was added successfully | ||
| } | ||
|
|
||
| func (be *BasicEnvironment) AllTrackedVariables() []Variable { | ||
| return be.Variables | ||
| } | ||
|
|
||
| /* | ||
| Public Functions | ||
| */ | ||
|
|
||
| func MakeBasicEnvironment(nameIn string) BasicEnvironment { | ||
| return BasicEnvironment{ | ||
| name: nameIn, | ||
| Variables: []Variable{}, | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| DefaultEnvironment | ||
| A variable that exists in the background and used to store information about the variables currently created. | ||
| */ | ||
| var DefaultEnvironment = MakeBasicEnvironment("DefaultEnvironment") |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Changing Environment from a concrete struct to an interface is a breaking API change. Consider adding a migration path: e.g., provide a type alias for the old struct (if applicable), document the change, and add deprecated wrapper constructors/functions that accept *BasicEnvironment to ease transition, or add helper constructors like NewBasicEnvironmentPtr() returning *BasicEnvironment for callers that previously passed *Environment.