[Day13] Greedy(貪婪) in Java

思路 最低成本 BFS 廣度優先搜尋 Breadth-First Search (最佳解) 實作 測試方法 public static void main(String[] args) { Integer[][] maze = new Integer[][] { {1,3,1,2,9}, {7,3,4,9,9}, {1,7,5,5,3}, {2,3,4,2,5}, }; Greedy_Maze_Cost_A gmc = new Greedy_Maze_Cost_A(maze); int row_start = 0; int col_start = 0; //起始位置 int row_target = 3; int col_target = 4; //目標位置 int cost_min = gmc.go_maze(row_start, col_start, row_target, col_target); System.out.println(); } public class Greedy_Maze_Cost_A { Integer[][] maze; // cost lookup table PriorityQueue<Node> pq; // explored nodes (sort by cost) Integer[][] maze_best; // unexplored nodes (null) + confirmed nodes // 節點初始化 row欄, col列, cost static class Node { Integer row; Integer col; Integer cost; public Node(Integer row, Integer col) { this....

August 15, 2022 · 2 min · Yish

Support Enum Type With Sqlite in Laravel Migration

The reference of this article is here. Recently, I have needed to upgrade the old version of laravel project, but in the migrations, I found that the enum type is not supported with sqlite in unit testing. Fortunately, I found the solution, here is the code: class UpdateUserStatus extends Migration { // if it doesn't set the type in sqlite, caused error; // [Doctrine\DBAL\DBALException] // Unknown database type enum requested, // Doctrine\DBAL\Platforms\MySqlPlatform may not support it....

August 12, 2022 · 1 min · Yish

How to Mock Request With Calling Third Party in Test?

In this case, I faced a problem when I want to mock a request with calling third party in test, I had two problem to wait for solving. Customzing the headers of the request for specific purpose. Mocking the third party requesting in test. Here is my thought: Finding mocked request in laravel TestCase Based on it and create a customize method of mocking request in test. Firstly, I found the method of get in TestCase, and it do some operation like:...

August 3, 2022 · 4 min · Yish

Redis switches main or backup in laravel

In my situation, I face a problem with redis, our redis service(RDS) is unstable with unknown problem, but I need to solve consistency service and zero-downtime, so on my first solve problem that I do switch service in my application. Here is my thinking steps: Redis service needs to bind container by singlton Trying to connect Master redis, if it’s failed, rebinding second redis service. Rebinding facade class to new redis service....

August 1, 2022 · 2 min · Yish

Modify Package by Composer

In newer laravel, we are use many ways to instead of https://github.com/Zizaco/entrust package doing works, but previous project still use it. for now, the project needs to upgrade to newer laravel, the package doesn’t support newer laravel, we can upgrade to suit our project by composer. Documentation Changes to * signature in composer.json "require": { "zizaco/entrust": "*" } cloning package For this project I put into /packages/ in application, app/ packages/ entrust/ repositories "repositories": [ { "type": "path", "url": "packages/entrust" } ], Finally you do composer update, you can customize or update the package by yourself, running the testing cases and more....

April 6, 2022 · 1 min · Yish

Trait Instead of the Other Trait Method

use AuditableWithOrder; use \OwenIt\Auditing\Auditable { AuditableWithOrder::transformAudit insteadof \OwenIt\Auditing\Auditable; } How to overwrite the trait on self or the others trait? It’s about vanilla PHP, here is documentation PHP: Traits - Manualhttps://www.php.net/manual/en/language.oop5.traits.php, here is an example. trait Taggable { public function slug() { return Str::slug($this->slug, '-'); } } For now, I don’t want to make a string slugging for slug, I would like changing to snake, in the past, I would like to do following:...

April 3, 2022 · 3 min · Yish