Optaplanner planning variable is NOT nullable BUT still assign to null - optaplanner

planning variable is NOT nullable. when I print out planning entity in variable listener for my shadow value, still in planning process NULL value still assign to planning variable??
planning entity:
// Planning variables: changes during planning, between score calculations.
#PlanningVariable(valueRangeProviderRefs = {"numberRange"})
private Integer number;
#ValueRangeProvider(id = "numberRange")
private List<Integer> numberRange;
#CustomShadowVariable(variableListenerClass = BoxUpdatingVariableListener.class,
sources = {#PlanningVariableReference(variableName = "number")})
private Integer shaodowNumber;
variable listener:
protected void updateShadowNumber(ScoreDirector scoreDirector, Box sourceBox) {
System.out.println("number:"+sourceBox.getNumber());
}
part of result:
02:24:46.832 [main ] INFO Solving started: time spent (74), best score (-3init/-90), environment mode (FULL_ASSERT), random (JDK with seed 0).
number:1
number:null
number:2
number:null
number:3
number:null
number:4
number:null
number:5
number:null
number:6
number:null
number:7
number:null
number:7
number:7
number:null
number:null
02:24:46.883 [main ] DEBUG CH step (0), time spent (125), score (-2init/-43), selected move count (7), picked move (Box-1 {null -> 7}).
number:1
number:null
number:2
number:null
number:3
number:null
number:4
number:null
number:5
number:null
number:6
number:null
number:6
number:7
number:6
number:null

This is usually the result of not running a construction phase
https://docs.optaplanner.org/7.14.0.Final/optaplanner-docs/html_single/index.html#constructionHeuristics
like this for example
<constructionHeuristic>
<constructionHeuristicType>STRONGEST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>

Related

How do you manually update the stock of a product?

I have created a field that inherits from saler.order_line that is called packaging (I count the container as a product that is in the warehouse) but at the time of creating the purchase order it is added in the same line as the product I am trying to the package is deducted from the stock but I can not get it. I have tried overwriting the write method but it fails me. Any ideas ?
Sorry for my bad english.
Best regards, Jose Antonio.
I have added a product that would act as a container in the same line of order and I want to get in the movement of stock.
modified sale form
def action_button_confirm(self, context=None):
zero_price = [x.product_id.name for x in self.order_line]
zero_env1 = [x.tipo_env_1.name for x in self.order_line]
context = dict(context or {})
procurement_obj = self.pool.get('procurement.order')
sale_line_obj = self.pool.get('sale.order.line')
res = {}
Move = self.env['stock.move']
warehouse = self.env['stock.warehouse']
item = self.quant_move_item_model.new({'quant': self.quant1.id})
item.onchange_quant()
self.assertEquals(item.source_loc, self.quant1.location_id)
for transfer in self.order_line:
moves = self.env['stock.move']
stock_location = self.env['stock.quant'].search([('product_id', '=', transfer.tipo_env_1.id)])
move = Move.create({
'name': transfer.tipo_env_1.name,
'product_id': transfer.tipo_env_1.id,
'restrict_lot_id': False,
'product_uom_qty':transfer.cantidad_1,
'product_uom': 1, #TODO: Change the test value 1 to produc_uom
'partner_id': 1, #TODO: Change the test value 1 to partner_id
'location_id': stock_location.id,
'location_dest_id': 1,
})
return super(sale_order,self).action_button_confirm()

How to get a maximum date among the list of past dates in drools?

From the List of Orders, i need to collect dates which are past to requesteffDate and requesteffTime and take the maximum of the past dates.
function boolean dateCheck(Date effdt, Date efftm) {
String efffdt = new SimpleDateFormat("yyyyMMdd").format(effdt);
String effftm = new SimpleDateFormat("HHmm").format(efftm);
Date effdttm = new SimpleDateFormat("yyyyMMddHHmm").parse(efffdt + "" + effftm);
return effdttm.before(new Date());
}
rule "finding past maximum date"
when
$company : Company( $date:requesteffDate, $time:requesteffTime, $reqdt : requesteffDate.getTime(), $reqtm : requesteffTime.getTime() )
eval(dateCheck($date,$time))
accumulate(Orders( effectiveDate != null,
effdate:effectiveDate.getTime()<$reqdt),
maxEffDate:max(effdate))
then
//error
While doing this,
accumulate(Orders(effectiveDate!=null,
effdate:effectiveDate.getTime()<$reqdt),
maxEffDate:max(effdate))
I am getting maxEffDate as -9223372036854775808 which when converted is showing 1940
Same I have tried using min functionn it is showing 2262.
My class goes like this.
Class Company{
private Date requesteffDate;
private Date requesteffTime;
private Employee emp;
private List<Orders> orderlist;
}
Class Orders{
private Date effectiveDate;
private Date effectiveTime;
}
-9223372036854775808 is Long.MIN_VALUE. This is conclusive for indicating that the accumulate doesn't find any Orders.
Make sure that you insert some matching Orders facts.
Add a guard that the maxEffDate is != Long.MIN_VALUE.
Discontinue the usage of Date as a time-of-day value: Either use LocalDate and LocalTime or combine date and time into a single Date value.
Take care that conversions of date and time are not affected by your locale settings.

I want to add lower limit constraints in portfolio optimization in Optaplanner exercise

I want to add lower limit constraints in portfolio optimization in Optaplanner
exercise.
In Portfolio optimization in Optaplanner, we can control ratio limit by controlling sector constraints, and can only control upper limit value which is given as Quantity Maximum.
I've tried 'add lower limit as Quantity Minimum, and change Hardscore by quantity minimum similarly as quantity maximum.' However, I failed to apply it.
Anyway, is there any better way to add lower limit constraints in portfolio optimization in Optaplanner?
Plz Help me!
If it's for example per region, just add quantityMillisMinimum field on Region:
public class Region extends AbstractPersistable {
private String name;
private Long quantityMillisMaximum; // In milli's (so multiplied by 1000)
// New field
private Long quantityMillisMinimum; // In milli's (so multiplied by 1000)
}
and a score rule to add the hard constraint:
// New rule
rule "Region quantity minimum"
when
$region : Region($quantityMillisMinimum : quantityMillisMinimum)
accumulate(
AssetClassAllocation(region == $region, quantityMillis != null, $quantityMillis : quantityMillis);
$quantityMillisTotal : sum($quantityMillis);
$quantityMillisTotal < $quantityMillisMinimum
)
then
scoreHolder.addHardConstraintMatch(kcontext,
$quantityMillisTotal - $quantityMillisMinimum);
end
Are you using portfolio optimization for anything serious? :)

Make transaction date modifiable when chosing per diem as the category for a new expense line

When adding a new expense line in Dynamics AX Enterprise Portal 2012 , you can choose some expense category which make the transaction date modifiable for the user. If the expense category is "per diem", the transaction date is not modifiable, but when I choose for example AirFare, the transaction date is modifiable.
What I want to know is what modification do I need to do to make the transaction date modifiable for the user when chosing "per diem" as the expense category.
I've found the solution:
In TrvExpTransAddEdit.ascx.cs there is a switch case which sets the boundfield to readonly:
case "TransDate":
boundField.FastTabSummary = FastTabSummary.Yes;
if (expenseType == ApplicationProxy.TrvExpType.Allowance)
{
TransDate i portalen bliver editér bar
boundField.Mandatory = false;
boundField.ReadOnly = true;
}
I've change the property readOnly = false and now the transaction date field is modifiable.

Drools - using accumulate to find min and max

I have a drools question which has been troubling me for some time. I want to find out the min and max price from a list of Item objects (contains price) using accumulate. A Member object (which contails list of Item objects) is inserted which contains the list of Items.
groovy/java source pseudo code
-------------------------------
class Item {
BigDecimal price
}
class Member {
List<Item>> items
}
...
droolsStatefulSession.insert(member)
session.fireAllRules()
...
rule.drl
---------
rule "rule1"
when
member : Member ($itemList : items)
/*
*/
then
System.out.println("condition met...")
end
Now the questions is in the above rule is it possible to if so how do I find out the item with the minimum Price and maximum price using drools accumulate feature. I do not want to use an java/groovy utility functions.
I see the "collect" feature allows to use "from" and then a datasource. I wonder if "accumulate" is similar to collect.
No need to use accumulate, just do something like
Item($lowestPrice : price, $id : id)
not Item(price > $lowestPrice, id < $id)
That's if your Items are inserted into the working memory.
I'm new to the drool rule and I'm trying to solve this issue.
You can find out min and max price of item simply - you have to write some rules and need to add two variable in the Order class:
Class Order
{
private List<Item> itemList;
private int highPrice;
private int lowPrice;
}
Using the following rule you can calculate min and max value of an item:
package com.sample
import com.sample.DroolsTest.Message;
rule "rule1"
when
$order : Order($itemList:itemList)
$item:Item() from $order.itemList
then
insertLogical($item);
end
rule "highPriceRule"
when
$order : Order()
$item:Item($price:price,price>=$order.getHighPrice())
then
$order.setHighPrice($item.getPrice());
end
rule "lowPriceRule"
when
$order : Order()
$item:Item($price:price,price<=$order.getLowPrice()||$order.getLowPrice()==0)
then
$order.setLowPrice($item.getPrice());
end
rule "highPrice"
salience -1
when
$order : Order()
then
System.out.println( "higher Item Price is "+$order.getHighPrice());
end
rule "LowPrice"
salience -1
when
$order : Order()
then
System.out.println( "Lower Item Price is "+$order.getLowPrice());
end
in main method you have to write this code and run it
List<Item> items=new ArrayList<Item>();
Item item1=new Item();
item1.setPrice(10);
Item item2=new Item();
item2.setPrice(20);
Item item3=new Item();
item3.setPrice(10);
Item item4=new Item();
item4.setPrice(5);
items.add(item1);
items.add(item2);
items.add(item3);
items.add(item4);
Order order=new Order();
order.setItemList(items);
ksession.insert(order);
ksession.fireAllRules();
output:---
Lower Item Price is 5
higher Item Price is 20
As I'm new to the drool rule I would like to ask if this is the correct procedure? Or is there another way to solve this problem?

Resources