Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WolfGoatCabbage
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OROBWorld
WolfGoatCabbage
Commits
84e7261c
Commit
84e7261c
authored
3 years ago
by
Paul A. Rubin
Browse files
Options
Downloads
Patches
Plain Diff
Tweaked the routine that reports MIP solutions and added a method to report CP solutions.
parent
3aefc109
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/wolfgoatcabbage/Problem.java
+57
-6
57 additions, 6 deletions
src/wolfgoatcabbage/Problem.java
with
57 additions
and
6 deletions
src/wolfgoatcabbage/Problem.java
+
57
−
6
View file @
84e7261c
...
...
@@ -56,17 +56,55 @@ public final class Problem {
int
nTrips
=
(
int
)
Math
.
round
(
obj
);
// Add each trip to the report.
for
(
int
t
=
1
;
t
<=
nTrips
;
t
++)
{
sb
.
append
(
"Time "
).
append
(
t
).
append
(
":\t"
);
if
(
t
%
2
==
0
)
{
// Even numbered trips are right to left.
sb
.
append
(
"Time "
).
append
(
t
).
append
(
":\t"
)
.
append
(
format
(
what
(
near
[
t
-
1
]),
what
(
transit
[
t
]),
what
(
far
[
t
]),
false
))
.
append
(
"\n"
);
sb
.
append
(
format
(
what
(
near
[
t
-
1
]),
what
(
transit
[
t
]),
what
(
far
[
t
]),
false
));
}
else
{
// Odd numbered trips are left to right.
sb
.
append
(
"Time "
).
append
(
t
).
append
(
":\t"
)
.
append
(
format
(
what
(
near
[
t
]),
what
(
transit
[
t
]),
what
(
far
[
t
-
1
]),
true
))
.
append
(
"\n"
);
sb
.
append
(
format
(
what
(
near
[
t
]),
what
(
transit
[
t
]),
what
(
far
[
t
-
1
]),
true
));
}
sb
.
append
(
"\n"
);
}
return
sb
.
toString
();
}
/**
* Generates a string summary of a solution.
*
* The first index in the matrix argument is time, the second is item.
*
* @param nTrips
* @param far
* @param carried
* @return
*/
public
static
String
report
(
final
int
nTrips
,
final
double
[][]
far
,
final
double
[]
carried
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"""
The farmer arrives at the left bank at time 0.
"""
);
// Add each trip to the report.
for
(
int
t
=
1
;
t
<=
nTrips
;
t
++)
{
sb
.
append
(
"Time "
).
append
(
t
).
append
(
":\t"
);
String
boat
;
int
c
=
(
int
)
Math
.
round
(
carried
[
t
]);
if
(
c
<
ITEMCOUNT
)
{
boat
=
ITEMS
[
c
];
}
else
{
boat
=
"nothing"
;
}
if
(
t
%
2
==
0
)
{
// Trip is far to near.
sb
.
append
(
format
(
what
(
flip
(
far
[
t
-
1
])),
boat
,
what
(
far
[
t
]),
false
));
}
else
{
// Trip is near to far.
sb
.
append
(
format
(
what
(
flip
(
far
[
t
])),
boat
,
what
(
far
[
t
-
1
]),
true
));
}
sb
.
append
(
"\n"
);
}
return
sb
.
toString
();
}
...
...
@@ -121,4 +159,17 @@ public final class Problem {
sb
.
append
(
String
.
format
(
"%-"
+
WIDTH
+
"s"
,
right
));
return
sb
.
toString
();
}
/**
* Reverses the 0-1 values in a vector.
* @param x a vector of 0-1 values
* @return the logical negation of x
*/
private
static
double
[]
flip
(
final
double
[]
x
)
{
double
[]
y
=
new
double
[
x
.
length
];
for
(
int
i
=
0
;
i
<
x
.
length
;
i
++)
{
y
[
i
]
=
1
-
x
[
i
];
}
return
y
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment